Re: Challenge: MySql result to drop down box
- From: "Rik" <luiheidsgoeroe@xxxxxxxxxxx>
- Date: Thu, 13 Jul 2006 23:19:28 +0200
Jim S wrote:
I have made the two changes you suggested but am still not receivingI think I have narrowed it down to the for loop causing the problem...
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>";
Well, let's build some error handling into it.
<?php
$username = mysql_real_escape_string($username);
$res=mysql_query("SELECT DISTINCT `job_name`
FROM `oats_jobs_users_laborCode`
WHERE `user`='$username'
ORDER BY `job_name`");
if($res===false){
echo 'Error in query: '.mysql_error();
} else {
if(mysql_num_rows($res)<1){
echo 'Query did not match any records.';
} else {
echo "<select name=jobname><option selected='selected'>Choose
One</option>";
while($row=mysql_fetch_row($res)){
echo "<option value='{$row[0]}'>{$row[0]}</option>";
}
echo "</select'>";
}
}
?>
--
Rik Wasmus
.
- References:
- Challenge: MySql result to drop down box
- From: Jim S
- Re: Challenge: MySql result to drop down box
- From: Rik
- Re: Challenge: MySql result to drop down box
- From: Rik
- Re: Challenge: MySql result to drop down box
- From: Jim S
- Re: Challenge: MySql result to drop down box
- From: Jim S
- Challenge: MySql result to drop down box
- Prev by Date: Re: Challenge: MySql result to drop down box
- Next by Date: Re: uploading a document and moving to a subfolder
- Previous by thread: Re: Challenge: MySql result to drop down box
- Next by thread: Re: Challenge: MySql result to drop down box
- Index(es):
Relevant Pages
|