OK now... Here's the scoop.
I have an array that gets it's values from a database (sorta). There are 12 rows in the database.
The array only shows 11 of them. It won't get the first value. Help...
The code:
Get the data from the database....
$catquery=("SELECT CategoryID FROM foodcategories ORDER BY CategoryName");
$catresult=mysql_query($catquery) or die('Query failed. ' .mysql_error());
$catrow=mysql_fetch_array($catresult);
How many rows are there?
[CODE]$r=mysql_num_rows($catresult);[/CODE]
Please put info into array
$i=0;
while($catrow=mysql_fetch_array($catresult))
{
$a=$catrow[CategoryID];
$catarray[$i]=$a;
$i++;
}
Show me the Catedory ID's!
<p>Row 0 = $catarray[0]</p>
<p>Row 1 = $catarray[1]</p>
<p>Row 2 = $catarray[2]</p>
<p>Row 3 = $catarray[3]</p>
<p>Row 4 = $catarray[4]</p>
<p>Row 5 = $catarray[5]</p>
<p>Row 6 = $catarray[6]</p>
<p>Row 7 = $catarray[7]</p>
<p>Row 8 = $catarray[8]</p>
<p>Row 9 = $catarray[9]</p>
<p>Row 10 = $catarray[10]</p>
<p>Row 11 = $catarray[11]</p>
<p>Row 12 = $catarray[12]</p>
<p>Rows = $r</p>
Yes, the last line shows "Rows = 12".
Yes, I know that if there are only 12 rows, $catarray[12] won't work (array's start at 0, usually). I put the last array line (12) in there to see if for some reason it was being populated.
Here is the output...
Row 0 = 9
Row 1 = 4
Row 2 = 10
Row 3 = 6
Row 4 = 11
Row 5 = 5
Row 6 = 7
Row 7 = 2
Row 8 = 15
Row 9 = 3
Row 10 = 17
Row 11 =
Row 12 =
Rows = 12
Now... Why isn't the first Category ID picked up?
It's wierd.... There are 12 different CategoryID's and the CategoryID I am missing is Cat ID 12.... Hmmmm...
I took off the ORDER BY and here is the new output...
Row 0 = 3
Row 1 = 4
Row 2 = 5
Row 3 = 6
Row 4 = 7
Row 5 = 9
Row 6 = 10
Row 7 = 11
Row 8 = 12
Row 9 = 15
Row 10 = 17
Row 11 =
Row 12 =
Rows = 12
Now Cat ID 12 shows up (row 8), but the very first Cat ID (value = ID 2) is missing... Hmmmm hmmmmm...