Re: Challenge: MySql result to drop down box



I have made the two changes you suggested but am still not receiving a
result set. Let me repost my modified code.

<?php
$res=mysql_query("SELECT DISTINCT job_name FROM
oats_jobs_users_laborCode where user='$username' order by job_name");
echo "<select name=jobname> <option default='default'>Choose
One</option>";
for ($i=0; $row=mysql_fetch_row($res); $i++)
{
echo "<option value='$row[0]'>$row[0]</option>";
}
echo "</select>";
?>


Hi,

Here's how I would have written the code to build the select box:

<?php
$res=mysql_query("SELECT DISTINCT job_name AS JOB_NAME FROM
oats_jobs_users_laborCode where user='$username' order by job_name") or
die('Query failed');

echo "<select name='jobname'><option SELECTED='SELECTED'>Choose
One</option>";
foreach($row as mysql_fetch_assoc($res)) {
echo "<option value='{$row[JOB_NAME]}'>{$row[JOB_NAME]}</option>";
}
echo "</select>";
?>

also, make sure that the $username variable doesn't have a quote (') in
it or the query will fail

regards,
shubeer

.



Relevant Pages

  • Re: Problem with if statement. Please help!
    ... Try this modified code. ... As you are using PhotoId which i think will be a autoincrement field ... ORDER BY PhotoId DESC"; ... <?php echo $photos->PhotoDesc ?> ...
    (comp.lang.php)
  • Re: Challenge: MySql result to drop down box
    ... Jim S wrote: ... Let me repost my modified code. ... Think about it, <?php ?> tags aren't nestable, why should they? ...
    (alt.php)
  • Re: Challenge: MySql result to drop down box
    ... I have made the two changes you suggested but am still not receiving a result set. ... Let me repost my modified code. ... Think about it, <?php ?> tags aren't nestable, why should they? ...
    (alt.php)
  • Re: Challenge: MySql result to drop down box
    ... Jim S wrote: ... Let me repost my modified code. ...
    (alt.php)
  • Bizzare form problem - Please Help!
    ... Sorry if this is a repost, I could not see the original. ... If I use the exact same page without a php extension, ... this to be a PHP as I will be linking dynamic data to drop down lists. ... .html file it is just fine, served as a .php file the form data is lost on a ...
    (php.general)