473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

displaying records on user choice

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
6 1897
ronverdonk
4,258 Expert 4TB
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
jasone
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
4,258 Expert 4TB
You are welcome and I'll see you again with more.

Ronald
Feb 13 '08 #4
jasone
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
4,258 Expert 4TB
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
jasone
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

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

Similar topics

7
by: WindAndWaves | last post by:
Hi Gurus Is it possible to display the time on a site using javascript. I want to show visitors the current time in New Zealand, but the javascript that I use actually displays the time on the...
1
by: Tim Graichen | last post by:
Good morning, I have a sub-form that displays records from a table as a continuous form. The table has several hundred records, but the subform only displays five or six records. The records do...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
9
by: Susan Bricker | last post by:
Greetings. I am having trouble populating text data that represents data in my table. Here's the setup: There is a People Table (name, address, phone, ...) peopleID = autonumber key There...
2
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
3
by: Richard Carpenter | last post by:
I understand how to use a dropdown list control to display the associated description value for a foreign key in a parent rather than the key itself, but I don't like having to disable the control...
8
by: bimeldip | last post by:
Hi, i would like to display the list of tables in a database in a drop down list then when user selects a table, the table will be dispalyed on the page. So far i've done this: <? $dbname =...
10
by: bettyboo | last post by:
Hi all I got some really useful advice from here with my last question so I'm back for more! Only my second post so please bear with me - I'm very new to this so this will probably not be as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.