Posted by Rik on 07/13/06 21:19
Jim S wrote:
>> 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>";
> I think I have narrowed it down to the for loop causing the problem...
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
Navigation:
[Reply to this message]
|