Results 1 to 6 of 6
Thread: Displaying Data from a Drop Down List
-
Displaying Data from a Drop Down List
5 May 2011 @ 11.14 I'm struggling with displaying details from a selected option in a drop down list.
I have a drop down list which is populated from a MYSQL query. I want the user to select an option and the values associated pulled from the database and displayed.
The dynamically populated drop down list is for "Brand" and when a user selects the brand from the drop down list I want the "supplier" of that brand to be displayed.
The code below is for dynamically populating the drop down list. I'm just not sure on how to produce the next step.
Many thanksCode:<form id="form1" name="form1" method="get" action="<?php echo $PHP_SELF; ?> "> <strong>Brand:</strong> <select name="select"> <option value="">--- Please Select Brand ---</option> <?php // Get records from database (table "name_list"). $list=mysql_query("select * from who_supplies_us_what order by brand asc"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<?php echo $row_list['brand']; ?>" <?php if($row_list['brand']==$select){ echo "selected"; } ?>><?php echo $row_list['brand']; ?></option> <?php // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form>
-
5 May 2011 @ 11.38 well, when the user submits the form, the selected brand will be stored in $_POST['select']. You can then use this value to select the supplier?
Pseudocode:
Code:<?php if(isset($_POST['select'])) { $brand=mysql_real_escape_string($_POST['select']); $result=mysql_query("SELECT supplier FROM suppliers WHERE brand='".$brand."'; $row=mysql_fetch_assoc($result); print $row['supplier']; } ?>
-
-
-
****** solved ******
5 May 2011 @ 14.06 Got it sorted Now. Many thanks for your help.
For anyone interested the I have posted the completed code below.
Code:<form id="form1" name="form1" method="POST" action="<?php echo $PHP_SELF; ?> "> <strong>Brand:</strong> <select name="select"> <option value="">--- Please Select Brand ---</option> <?php // Get records from database (table "name_list"). $list=mysql_query("select * from who_supplies_us_what order by brand asc"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<?php echo $row_list['brand']; ?>" <?php if($row_list['brand']==$select){ echo "selected"; } ?>><?php echo $row_list['brand']; ?></option> <?php // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <br /> <p> <?php if(isset($_POST['select'])) { $brand=mysql_real_escape_string($_POST['select']); $result=mysql_query("SELECT supplier FROM who_supplies_us_what WHERE brand='".$brand."'"); while ($row=mysql_fetch_assoc($result)) { echo '<strong>Supplier: </strong>'; echo $row['supplier']; echo '<br />'; } } ?>
-
5 May 2011 @ 19.23 Hope that helps.PHP Code:
if(isset($_POST['select']))
{
$brand=mysql_real_escape_string($_POST['select']);
$result=mysql_query("SELECT supplier FROM suppliers WHERE brand='".$brand."'";
while( $row=mysql_fetch_assoc($result)) {
print $row['supplier'];
}
}
Similar Threads
-
Drop Down Menu
By silversurfer5150 in forum Javascript LibrariesReplies: 1Last Post: 15 Aug 2010, @ 07.28 -
displaying db records in groups?
By ljackson in forum PHP, ASP & JavaReplies: 8Last Post: 19 Jan 2010, @ 12.12 -
Drop shadow container
By trixiemay in forum HTML & CSSReplies: 2Last Post: 18 Jan 2010, @ 16.12 -
populating a list box with data from an array?
By ljackson in forum PHP, ASP & JavaReplies: 12Last Post: 22 Dec 2009, @ 15.23 -
Google tells users to drop IE6
By WelshStew in forum Coffee HouseReplies: 5Last Post: 26 Jan 2009, @ 20.11



LinkBack URL
About LinkBacks














Mobile device web design...
Hello there, Developing a mobile website is easy; there are many...