John,

I'm still not quite there, I can see the misty shape of a solution but the details are still a bit hazy.

The code I posted it the whole shebang. I've made some attempts to 'form enable' it, but can't figure out where to put the <form.../form>, and submit stuff so the entire thing renders as a form and creates the variable you describe.

I have built a php/html form with simple single value fields but can't see how to get from there to the sql populated dropdown etc...

It would be a huge favor if you could sketch out the blocks of php and html with a text description of what goes in the blocks so I could at least get started.

Part of what I'm struggling with is that there are at least 3 ways to do everything and whenever I find examples that are close to what I need, the layout is totally different from whatever I've pasted together before or uses a different php/sql/htlm method so I wind up starting over and getting back into a corner again. Programming is worse than English!

Thank you so much for your reply. I'm going to start hacking to see if I can get something working and will check back here later.

TIA

Doug

John W. Holmes wrote:
From: "Doug F" <[EMAIL PROTECTED]>

Populate a dropdown list with values from a MySQL db (done and working).
Use the selected value as the 'where' clause in a second query.
Return the results and display them to the user.

Any pointers are appreciated - noob^3 (html, mysql, and php).

Doug

Code that I'm using:

<html>
<body>
<?php

// connect to db
$db = mysql_connect("localhost");
mysql_select_db("test",$db);

// build query
$sitequery = "SELECT site from sitedata order by site";

// generate result set
$siteresult = mysql_query($sitequery);

// use results
echo "Select a site from the list below: <br><br><select name='site'>";
while($siterow = mysql_fetch_array($siteresult))
   echo "<option value='".$siterow["site"]."'>"
$siterow["site"]."</option>";
echo "</select></td>";


When the form is submitted, the value chosen will be in $_REQUEST['site']
(or $_GET['site'] or $_POST['site'], depending upon your form method).

Then just create your query:

$query = "SELECT * FROM sitedata WHERE site = '{$_REQUEST['site']}'";

If magic_quotes_gpc is not ON, then you'll want to run mysql_escape_string()
on the value first.

$site = mysql_escape_string($_REQUEST['site']);
$query = "SELECT * FROM sitedata WHERE site = '$site'";

See the recent threads on SQL Injection for a reason why. :)

---John Holmes...

-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to