Jump to content

mySQL Driven Listbox Problem


deepdiver30

Recommended Posts

I have a PHP Form with a list box.  The list box contains value queried from a mySQL database and the control on the form is generated programatically within PHP and echo'd to the screen, which works fine, however I am having trouble trying to find out from the PHP code what the user has selected.

 

I want to be able to record the user's selection in a variable so that i can then perform another query based on the initial selection. 

 

Some places I have read, I need to use JavaScript to do this, other places think that I can do this within HTML and somehow echo the results from the query into the HTML via PHP - I'm confused ???

 

I hope this makes sense, but let me know if you need any clarification, code examples etc.

DeepDiver30

Link to comment
Share on other sites

Code as suggested - this is dev only at the moment

<?php

//Setup Connection to Database

$user="root";

$host="localhost";

$password="password";

$database="DiggersDirect";

$connection = mysql_connect($host,$user,$password) or die ("Could Not Connect");

$db = mysql_select_db ($database,$connection) or die ("Could Not Select");

//Build and Run the Query

$query = "SELECT DISTINCT description FROM machines ORDER BY DESCRIPTION";

$result = mysql_query($query) or die ("Could not execute Query");

//Display HTML Select Box

echo "<select name='description'>\n";

//Loop to get everything

while ($row = mysql_fetch_array($result))

{

extract($row);

echo "<option value='$description'>$description\n";

}

echo "</select>\n";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.