Re: [PHP-DB] Splitting Product Catalogue Over Multiple Pages?
Gary, thanks for your reply, I think I'll need 2 have a think about this. I didn't totally understand: You limit the query by LIMIT starting_point,number_of_records_to_return at the end of the sql statement. I've never used LIMIT before, could you explain this a bit more or point me to some info? Cheers, Graeme :) - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, June 27, 2003 2:39 PM Subject: RE: [PHP-DB] Splitting Product Catalogue Over Multiple Pages? If you're trying to do paging, it's quite simple (there are tons of examples out there, search google for paging php) $sql = select count(*) from table_name $number_of_records = mysql_query($sql); $pointer=0; $recs_per_page=20; if($number_of_records $recs_per_page) { // do a limit and keep the pointer $sql = select * from other_table limit $pointer,$recs_per_page; $pointer += $recs_per_page; This isn't complete by any means but the point should be clear. You limit the query by LIMIT starting_point,number_of_records_to_return at the end of the sql statement. Don't worry about the values in the column, just the amount of records you want to return Gary Every Sr. UNIX Administrator Ingram Entertainment (615) 287-4876 Pay It Forward mailto:[EMAIL PROTECTED] http://accessingram.com -Original Message- From: Boa Constructor [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 10:25 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Splitting Product Catalogue Over Multiple Pages? Greetings all, I'm not sure if this has been discussed recently, I've read bits and pieces and I can't remember where I read everything so if it has been brought up recently - sorry. If I do an SQL (MySQL) query on the first example to get the min and max IDs then I will get 1 and 6 respectively. I will then be able to loop from 1 to 6 and return all 6 products from the database. If however I wanted to split this in to two pages with 3 items in each page then using the first example below I could grab the min ID and add 2 to it to make 3. I could not do this using the second example because if I grab the min ID I would get 3, if I add 2 to it then I would get 5. 5 does not exit in this table so that wouldn't work. How in example 2 would I be able to split this over two pages? //example 1 ID Product_Name 1 Hoover 2 Kettle 3 Fridge 4 Cooker 5 Food Mixer 6 TV //example 2 ID Product_Name 3 Fridge 4 Cooker 7 Microwave Oven 8 Freezer 9 DVD Player 10 Computer Any ideas? Anything is much appreciated. Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] re:[PHP-DB] Splitting Product catalog
Michael, thank you so much for that code. I think I could maybe get this working properly. I've got 2 categories and 4 products in each and I want to split them in to 2 pages, 2 products on each. So obviously I will have 2 links at the bottom page 1 2.. etc when I click the link 2 I will need 2 tell the database to look up the 3rd and 4th record. So would it be possible to pass a parameter in the URL such as newpage=2 then multiply it by 2 and use that as the maximum limit then take 1 away from that value and use that as the minimum limit in the SQL query? Basically: 2x2 = 4 (maximum limit) 4-1 = 3 (minimum limit) Would this work? Cheers, Graeme :) - Original Message - From: Michael Lewis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 27, 2003 3:47 PM Subject: [PHP-DB] re:[PHP-DB] Splitting Product catalog Graeme, Use a select string as in, $sel=select * from product where price100 order by price LIMIT 0,100; This would result in the query only returning the first 100 records. If you want to page through them (back and next links). You would have to save the current start point and the length would be the number of records you want to display. Take the following example (please) which selected records in groups of tens: session_start(); $start=$_SESSION['start']; sel=select count(*) from product; $res=mysql_query($sel) or die(mysql_error()); $r=mysql_fetch_array($res); $totalmsg=$r[0]; if ($start$totalmsg) { $start=0; $_SESSION['start']=0; } $res=mysql_query($sel) or die(mysql_error); $numtoprocess=10; $numselected=mysql_num_rows($res); if ($numselected$numtoprocess) { $numtoprocess=$numselected; } $sel=select * from product limit $start,$numtoprocess; for ($i=0;$i$numtoprocess;$i++) { process the record here } $start+=$i; $_SESSION['start']=$start; yada, yada, yada (put your back and next buttons here) The above code is stripped of most error checking etc., but it should give you a framework to get started. Michael Lewis -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Splitting Product Catalogue Over Multiple Pages?
RE: [PHP-DB] Splitting Product Catalogue Over Multiple Pages?Ahhh rite, I think I get this, I've just posted another question but I think I it will work if I do it the way I suggest in my last post. If not please let me know. Thank you both Gary and Michael! Cheers, Graeme :) - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] ; [EMAIL PROTECTED] ; [EMAIL PROTECTED] Sent: Friday, June 27, 2003 3:44 PM Subject: RE: [PHP-DB] Splitting Product Catalogue Over Multiple Pages? LIMIT 0,10 will return the first ten records of a result set. To make more sense, you should do an ORDER BY of some field to get the info sorted correctly. LIMIT takes 1 or two arguments If there is only one argument, say 10, it will return the first ten records. If there are two arguments, LIMIT 20,10 it will return 10 records starting at record 20. More info at http://www.mysql.com/doc/en/SELECT.html Search for limit on that page. Gary Every Sr. UNIX Administrator Ingram Entertainment (615) 287-4876 Pay It Forward mailto:[EMAIL PROTECTED] http://accessingram.com -Original Message- From: Boa Constructor [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2003 9:20 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP-DB] Splitting Product Catalogue Over Multiple Pages? Gary, thanks for your reply, I think I'll need 2 have a think about this. I didn't totally understand: You limit the query by LIMIT starting_point,number_of_records_to_return at the end of the sql statement. I've never used LIMIT before, could you explain this a bit more or point me to some info? Cheers, Graeme :) - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Friday, June 27, 2003 2:39 PM Subject: RE: [PHP-DB] Splitting Product Catalogue Over Multiple Pages? If you're trying to do paging, it's quite simple (there are tons of examples out there, search google for paging php) $sql = select count(*) from table_name $number_of_records = mysql_query($sql); $pointer=0; $recs_per_page=20; if($number_of_records $recs_per_page) { // do a limit and keep the pointer $sql = select * from other_table limit $pointer,$recs_per_page; $pointer += $recs_per_page; This isn't complete by any means but the point should be clear. You limit the query by LIMIT starting_point,number_of_records_to_return at the end of the sql statement. Don't worry about the values in the column, just the amount of records you want to return Gary Every Sr. UNIX Administrator Ingram Entertainment (615) 287-4876 Pay It Forward mailto:[EMAIL PROTECTED] http://accessingram.com -Original Message- From: Boa Constructor [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 10:25 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Splitting Product Catalogue Over Multiple Pages? Greetings all, I'm not sure if this has been discussed recently, I've read bits and pieces and I can't remember where I read everything so if it has been brought up recently - sorry. If I do an SQL (MySQL) query on the first example to get the min and max IDs then I will get 1 and 6 respectively. I will then be able to loop from 1 to 6 and return all 6 products from the database. If however I wanted to split this in to two pages with 3 items in each page then using the first example below I could grab the min ID and add 2 to it to make 3. I could not do this using the second example because if I grab the min ID I would get 3, if I add 2 to it then I would get 5. 5 does not exit in this table so that wouldn't work. How in example 2 would I be able to split this over two pages? //example 1 ID Product_Name 1 Hoover 2 Kettle 3 Fridge 4 Cooker 5 Food Mixer 6 TV //example 2 ID Product_Name 3 Fridge 4 Cooker 7 Microwave Oven 8 Freezer 9 DVD Player 10 Computer Any ideas? Anything is much appreciated. Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Splitting Product Catalogue Over Multiple Pages?
Greetings all, I'm not sure if this has been discussed recently, I've read bits and pieces and I can't remember where I read everything so if it has been brought up recently - sorry. If I do an SQL (MySQL) query on the first example to get the min and max IDs then I will get 1 and 6 respectively. I will then be able to loop from 1 to 6 and return all 6 products from the database. If however I wanted to split this in to two pages with 3 items in each page then using the first example below I could grab the min ID and add 2 to it to make 3. I could not do this using the second example because if I grab the min ID I would get 3, if I add 2 to it then I would get 5. 5 does not exit in this table so that wouldn't work. How in example 2 would I be able to split this over two pages? //example 1 ID Product_Name 1 Hoover 2 Kettle 3 Fridge 4 Cooker 5 Food Mixer 6 TV //example 2 ID Product_Name 3 Fridge 4 Cooker 7 Microwave Oven 8 Freezer 9 DVD Player 10 Computer Any ideas? Anything is much appreciated. Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] extract( $HTTP_POST_VARS ); ------------ what does this do?
I'm wanting to overwrite the variables contained in a session, I read on the net somewhere that I could do this by explicitely making variables global, the code I looked at contained this: extract( $HTTP_POST_VARS ); What exactly does this do? Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: extract( $HTTP_POST_VARS ); ------------ what does this do?
Pete, I got my problem sorted out, thanks for directing me to the manual. I'm not too fond of the manual as I find it difficult to understand as I'm sure many newbies do. Turns out I didn't have to use that function but thank you anyway! Cheers, Graeme :) - Original Message - From: Pete Morganic [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, June 24, 2003 6:32 PM Subject: [PHP-DB] Re: extract( $HTTP_POST_VARS ); what does this do? http://uk2.php.net/extract Boa Constructor wrote: I'm wanting to overwrite the variables contained in a session, I read on the net somewhere that I could do this by explicitely making variables global, the code I looked at contained this: extract( $HTTP_POST_VARS ); What exactly does this do? Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Session Question
Greetings all, Now that my shopping cart is just about complete I've been working on the rest of the order process. I have got two pages before finally placing an order. The first page takes address details and the next page prints them all out with the contents of the shopping cart so the user can verify that they are correct. I have put an Edit button on it so that the user can go back and change address details. The problem is this. I am using sessions to store the address details and when the user clicks Edit the current details are printed out which is expected. When the user changes any of these details they aren't recorded in the session and so only the original values are recorded in the session and aren't overwritten or changed. I have got calls to session_register(); for each variable on the address details page and also on the confirmation page. Any ideas? Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Email confirmation?
Greetings every1 I'm wondering how I can send the details of an order to an email address. I have a foreach loop which loops through an array and each time round the loop it runs a query on the database to get product details. If for instance they ordered 5 different items then I would need to loop 5 times to get all the product information. The way I see it, I can't make a call to the mail() function within the foreach loop as that would send out an email for each product ordered. Any ideas how to send all the order information all in one email? Cheers for any ideas, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Removing cart items with hyperlink question
Hey all, OK, I've made quite a bit of progress with my shopping cart and I'm at the stage of removing items from it. If I change the quantity to 0 and click the submit button the item is removed. However it isn't obvious how to remove items so I want to put a link next to each item that says Remove Item. The first line below works but the second one doesn't. If $quantity were to equal 0 then I want both of these to do exactly the same thing. echo Input type=text size=2 name=quantity[$buy] value=$quantity; echo a href=$PHP_SELF?quantity[$buy]=0Remove Item/abr; Any ideas? Cheers, G :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Passing URL parameters to array question.
Hey all, anyone know how I can pass an array of parameters to an array? Basically if I want to pass the parameters in a URL, for example: viewcart.php?quantity%5B14%5D=2TypesOfInterests=11recalculate=true I'm using the following but it ain't workin so far. foreach($shoppingcart['products'] as $buy = $quantity) { if ($_GET['buy'] == $buy) { // if we are here, we know this is the one $shoppingcart['products'][$buy] = $_GET['quantity']; } When I view the cart at the moment only the value passed in the 1st instance are assigned to the array. Any ideas? Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Shopping Cart Updating Quantities Question.
Greetings all, Ok, I've made some progress with my shopping cart. I can now update the quantity of one item only. When I try to update the quantities of 2 products it only lists the first product with its previous quantity. I also need to press the update quantity button twice for the quantity to be changed. How can I update quantities of more than one product and why do I have to press the update quantity button twice? Here's the product catalogue: http://www.hostmaster-x.co.uk/DisplayProducts.php?TypesOfInterests=11 The values are passed to the URL and the code I'm using to update quantities is as follows: foreach($shoppingcart['products'] as $buy = $quantity) { if ($_GET['buy'] == $buy) { $shoppingcart['products'][$buy] = $_GET['quantity']; } Any ideas ppl? Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Array Question
Hello everyone. If I wanted to pass a item ID along with a quantity to an associative array called CartArray how would I pass it to the PHP script? I'll get this shopping cart working yet !! Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Array Question
RE: [PHP-DB] Array QuestionCheers Gary, and in the html would I put something like: a href=myscript.php?itemid=1qty=2buy this item/a Simple question I know! Jay, yup thats all I want to do, just assign two values into an array. Thank you, Graeme :) - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] ; [EMAIL PROTECTED] Sent: Monday, June 02, 2003 8:30 PM Subject: RE: [PHP-DB] Array Question CartArray['itemid'] = $itemid; note where $qty = CartArray['qty']; /note Gary Every Sr. UNIX Administrator Ingram Entertainment (615) 287-4876 Pay It Forward mailto:[EMAIL PROTECTED] http://accessingram.com -Original Message- From: Boa Constructor [mailto:[EMAIL PROTECTED] Sent: Monday, June 02, 2003 2:27 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Array Question Hello everyone. If I wanted to pass a item ID along with a quantity to an associative array called CartArray how would I pass it to the PHP script? I'll get this shopping cart working yet !! Cheers, Graeme :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Adding elements to array question
Hey again all, right I've tried using an associative array for my shopping cart and I've encountered two problems - so far. The first problem is that I can't only add one item to the cart and the second problem is that when viewing the cart it shows two items in it. I think this is because there are two parts to the array, buy and quantity and when I'm counting the amount of items in the array its counting all the components of the array. How can I add items to the end of this associative array? Some of the code I'm using is below. I'm also thinking that if the below code works then there is something wrong with the way I'm reading back the items in the cart. Ugh I dunno! Any ideas? Cheers, Graeme :) ?PHP session_start(); session_name('shoppingcart'); if($buy != ) { $shoppingcart = array( 'buy'='$buy', 'quantity'='$quantity' ); session_register('shoppingcart'); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Shopping Cart Sessions - Think this is a simple prolem- hopefully
Peter, thanks for your reply. I'm 100% unsure that register_globals is turned on. I've not tried any of your points as for some reason my code works and my errors have somehow disappeared. It simply doesn't make any sense. Although I did email my web host to see if register_globals were turned on and they may have done this, but I'm thinking its not that as nobody has got back to me. I printed out the contents of the $buy variable and it contained exactly what I expected it to so it seems to be behaving as it should, I'm just unsure as to why its working now - bizarre! Even when I passed the Catagory/Interests ID along with the product ID in the URL, that still produced errors but I wasn't going to stay up any later to try and solve it. All I know is last night is didn't work and now it does ! Thanks again for your reply. Graeme :) - Original Message - From: Peter Beckman [EMAIL PROTECTED] To: Boa Constructor [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, November 14, 2002 3:41 PM Subject: Re: [PHP-DB] Shopping Cart Sessions - Think this is a simple prolem- hopefully 1. Are you 100% sure register_globals is turned on? 2. You session_register your variable before you change it. Replace $ShoppingCart with $_SESSION[ShoppingCart] every time you use it. This way you are modifying the session variable actually in the session, not just the one time. session_register() copies the named variable into the session space, but adding or removing items from that variable does NOT change it in the session if you use _register. If you modify $_SESSION[shoppingcart] every time, then you are actually reading/writing to the real session variable and don't have to worry about it. Peter On Thu, 14 Nov 2002, Boa Constructor wrote: Evening all, I'm pretty stumped with this basic shopping cart I'm trying to integrate into my site, if u wanna see what I'm on about visit http://www.hostmaster-x.co.uk/Products.php. On my products script I've got the following: [...] Of course I need a link so that I can buy a product, so I've got the following in a loop: echo a href=$PHP_SELF?buy=$iBuy/aBR; The link works fine for each product, the problem is that the ID of the product doesn't seem to be stored in the session and I get a whole pile of mysql errors which don't appear in the same page when products are displayed. The errors highlight the following code: while($ProductDetails = mysql_fetch_array($Q)) { $ProductID = $ProductDetails[ID]; $ProductName = $ProductDetails[ProductName]; $SellingPrice = $ProductDetails[SellingPrice]; $ProductPicture = $ProductDetails[PictureOfProduct]; $AmountInStock = $ProductDetails[AmountInStock]; $Description = $ProductDetails[ProductDescription]; $PictureOfProduct = $ProductDetails[PictureOfProduct]; } if(mysql_num_rows($Q) 0) Anyone got any ideas? I'm a bit lost as to why this doesn't work. G :) -- - Peter BeckmanSystems Engineer, Fairfax Cable Access Corporation [EMAIL PROTECTED] http://www.purplecow.com/ -- - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Shopping Cart Sessions - Think this is a simple prolem - hopefully
Evening all, I'm pretty stumped with this basic shopping cart I'm trying to integrate into my site, if u wanna see what I'm on about visit http://www.hostmaster-x.co.uk/Products.php. On my products script I've got the following: ?php $shoppingcart = array(); session_start(); session_register('shoppingcart'); if($buy != ) { $shoppingcart[] = $buy; //header(Location: $PHP_SELF); /* echo BCart contains: ?=count($shoppingcart)? items/BBRBRBR; */ //exit(); } // Loads more code here ( code that works ) Of course I need a link so that I can buy a product, so I've got the following in a loop: echo a href=$PHP_SELF?buy=$iBuy/aBR; The link works fine for each product, the problem is that the ID of the product doesn't seem to be stored in the session and I get a whole pile of mysql errors which don't appear in the same page when products are displayed. The errors highlight the following code: while($ProductDetails = mysql_fetch_array($Q)) { $ProductID = $ProductDetails[ID]; $ProductName = $ProductDetails[ProductName]; $SellingPrice = $ProductDetails[SellingPrice]; $ProductPicture = $ProductDetails[PictureOfProduct]; $AmountInStock = $ProductDetails[AmountInStock]; $Description = $ProductDetails[ProductDescription]; $PictureOfProduct = $ProductDetails[PictureOfProduct]; } if(mysql_num_rows($Q) 0) Anyone got any ideas? I'm a bit lost as to why this doesn't work. G :) Public Sub House() On Error Resume drink If Pint.empty = True Then Pint.refill Else Pint.drink End if stomach.add Pint MsgBox I've had stomach.count Pints MsgBox VERY DRUNK End Sub
Re: [PHP-DB] upload data to MySql
I'm new to file uploads, however I managed to get it working. Are you copying the file after its been uploaded? If not you need to do this as the temp file is destroyed after the script has finished running so you need to copy it if you wish to store it. You also will have to chmod 777 to the directory you wish to copy the file to. It may help if we can see the tutorial to try and find out exactly what you are doing. I've been working from Build Your Own Database Driven Website Using PHP MySQL By Kevin Yank and its really helpful it covers file uploads. I'm also using PHP and MySQL Web Development by Luke Wellling and Laura Thomson. This covers file uploads also, infact I found it more helpful for file uploads. Hope this helps. Cheers, G :) - Original Message - From: Seabird [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 13, 2002 8:47 PM Subject: [PHP-DB] upload data to MySql Hi everyone, I don't get my upload to work properly. It's a tutorial of the web, but it doesn't function (unless I made a mistake). Please help me... I have a form passing on 5 fields (text for testing), name: year, make, model, price, picture and submit to PHP_SELF ?php if ($submit) { $db = mysql_connect(localhost,myname,mypassword); mysql_select_db($test,$db); //DB Test for testing... $sql = INSERT INTO test (year,make,model,price,picture) VALUES ('$year,$make,$model,$price,$picture'); //I created these columns in the table test echo year: $yearbr\n; echo make: $makebr\n; echo model: $modelbr\n; echo price: $pricebr\n; echo picture: $picturebr\n; } ? I know I need globals on for this. Thanx for the help, Jacco -- http://seabird.jmtech.ca Attitude is Everything! But Remember, Attitudes are Contagious! Is Yours worth Catching -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php