You are here: Re: Challenge: MySql result to drop down box « All PHP « IT news, forums, messages
Re: Challenge: MySql result to drop down box

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация