By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

displaying records on user choice

P: 66
Hi all!
im developing a system where a user can select what flower goes into their bouquet, and ive become a little bit stuck... heres what ive done to date:

currently ive got a page displaying a tables records (the flowers) the page has a checkbox next to each record where the record primary key has been assigned to the checkbox.

once the user select the items and clicks sumbit it takes them to a 'choice' page to display the flowers they have chosen. ive tried both the get and post functions and found that the get function displays all the keys in the url but when i try to read out the urls it only displays the last one, confused? ok

so ive selcted items 3 and 4 in the list and select submit... in the url it shows: choice.php?flowerid=3&flowerid=4.
but when i try to call these on the screen... records 3 and 4 it will only show record for...

so heres the code im using for the submit page and action page:
-------------------------submit page------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?PHP 
  2. $qry = mysql_query ('SELECT * FROM flowers');
  3. $result = mysql_fetch_array($qry);
  4. ?>
  5. <body>
  6. <form name="choice" action="choice.php" method="GET">
  7. <?PHP 
  8.  
  9. while ($row = mysql_fetch_array($qry)){ 
  10.  
  11. echo  $row['flowername']; ?>
  12. <input type="checkbox" value="<?php echo $row['flowerid']; ?>" name='flowerid'>
  13. <?PHP
  14. }
  15.  
  16. ?> 
  17. <input type="submit" value="submit" />
  18. </form>
  19.  
-------------------------------------------------------------------------
-------------------action page------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include "constants/flowertimedbcnx.php";
  3.      $r = @$_GET['flowerid']; //users choice..
  4.      $s = @$_GET['flowername'];
  5.  
  6.      ?>
  7.           <?php 
  8.       echo "You have chosen to buy flowers for your
  9.  
  10.  
  11.        <b>$r, $s</b>.";
  12. ?>
  13.  
-------------------------------------------------------------------------

if you need anymore information to help please let me know...

ive also tried replacing the 'GET' with 'POST' but it still on displays the last record passed., but using 'GET' it showed that the 2 record ids were being passed.


many thanks in advance!
Feb 12 '08 #1
Share this Question
Share on Google+
6 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Firstly, the first statement [php]$result = mysql_fetch_array($qry);
[/php] must be removed, otherwise you skip the first row of your result.

Secondly, the name 'flowerid' is identical for each input statement, so your $_GET array can contain only one entry $_GET['flowerid'] because there can only be 1 associative key flowerid in the $_GET array.
So you must make the selection name an array by defining the name of the input field as 'flowerid[]' as in:
[php]<input type="checkbox" value="<?php echo $row['flowerid']; ?>" name='flowerid[]'>[/php] This will make flowerid an array in the $_GET array. So when you want to check the checked flowerids you must walk array flowerid to get all choices. Add the following statements at the top of your choice.php script and you will see how it works.
[php]echo 'You have chosen the following flowerids:<br>';
foreach($_GET['flowerid'] as $flower) {
echo "$flower<br>";
}[/php]

Good luck.

Ronald
Feb 12 '08 #2

P: 66
I bow down before you!

thanks very much for your help... i will probably be posting allot more queires for this system. but this is a big step in the right direction... thanks bery much ronald !
Feb 13 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
You are welcome and I'll see you again with more.

Ronald
Feb 13 '08 #4

P: 66
ok, now im stuck again.. trying to get the flowerids to display other relevant fields in the database:

heres what ive tried to display relating data:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include "constants/flowertimedbcnx.php";
  3.  
  4.       echo 'You have chosen the following flowerids:<br>';
  5.  
  6.       foreach($_GET['flowerid'] as $flower) {
  7.  
  8.           echo "$flower<br>";
  9.       }
  10.       ?>
  11.  
  12.  <?PHP 
  13.  $sql = 'SELECT * FROM flowers WHERE flowerid = '. $flower;
  14.  
  15.  while ($row = mysql_fetch_array($sql)){ 
  16.  
  17. echo  $row['flowername']; 
  18. echo "<br>";
  19. }
  20.  
  21.  
  22.  ?>
  23.  
hope this can be done easily :-)
Feb 13 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
Yes it can. Best way is to display the flowername within the foreach construct, as follows:
[php]
echo 'You have chosen the following flowerids:<br>';
foreach($_GET['flowerid'] as $flower) {
$res = mysql_query ("SELECT * FROM flowers WHERE flowerid = $flower");
while ($row = mysql_fetch_array($res)) {
echo "$flower = {$row[flowername]} <br>";
}
}[/php]
Ronald
Feb 13 '08 #6

P: 66
hey, ive sent you a pm ron!

next step is adding the selected flowers to a table... so multiple rows, identifed by a session username... have psoted a thread for this as i didnt want to be realy cheeky and ask for your support on this... but here's the link to it.:

http://www.thescripts.com/forum/thread770700.html

many thanks

jason!
Feb 13 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.