Re: Simple while loop skipping first row of array
| From: | Verdon Vaillancourt | Date: | Sun, 15 Feb 2004 20:44:28 +0000 |
| Subject: | Re: Simple while loop skipping first row of array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-177747@lists.php.net to get a copy of this message | ||
That did the trick, and I learned something new. thanks :)
verdon
On 2/15/04 11:38 AM, "Duncan" <php-general@ring-wraith.com> wrote:
> Problem is, that the first row is already in the $categories variable -
> since you have the first mysql_fetch_array call there.
> change it to:
>
> echo "<select name=\"cats\">";
> $result = mysql_query("select * from cats order by title");
> while ($c = mysql_fetch_array($result)) {
> echo "<option value=\"$c[id]\">$c[title]</option>";
> }
> echo "</select>";
>
>
> ...and it should work just fine.
>
> Verdon Vaillancourt wrote:
>
>> I'm not sure I phrased my subject well, but...
>>
>> The following is just to build a select menu from a table query result set.
>> It sort of works, but doesn't return the first row in the result set, ie if
>> I have the following rows in the table 'cats';
>>
>> id title
>> ==========
>> 1 Pears
>> 2 Oranges
>> 3 Apples
>> 4 Bananas
>>
>> echo "<select name=\"cats\">";
>> $result = mysql_query("select * from cats order by title");
>> $categories = mysql_fetch_array($result);
>> if ($categories) {
>> while ($c = mysql_fetch_array($result)) {
>> echo "<option value=\"$c[id]\">$c[title]</option>";
>> }
>> }
>> echo "</select>";
>>
>>
>> The resulting select menu will only include Bananas, Oranges, Pears.
>>
>> Am I missing something terribly obvious to one less newbie than me?
>>
>> TIA,
>> Verdon
>>
>>
>>
>
>
>