Page 1 of 1

[SOLVED]Code doesn't display row[i] values in table??

Posted: Mon Dec 12, 2011 4:25 pm
by jellis00
My below listed code generates a two column table into which I want to populate the values in arrays $times and $temps. The $times values are appearing correctly in the 1st column of the table. However, the values in the array elements of $temps donot appear in the table. Can anyone tell me where my code went wrong in doing this??

Code: Select all

<?php     
    $query = "SELECT * FROM temphistory WHERE `iChipID` = '$theSerial' " ;
	$temps = mysql_query($query) or die ("Couldn't execute query.");
	$times = array("NA","NA","00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00") ; 
	$row = mysql_fetch_row($temps);
	
	//output the arrays in HTML to a table  
	echo '<table border="1">';  
	echo '<tr><td>Time</td><td>Temperature</td></tr>';  
	for($i=2;$i<=25;$i++)
	{
		echo "<tr>\n
     		<td>$times[$i]</td>\n
     		<td style='text-align: right'>$row[$i]</td>\n  
     		</tr>\n";  
 	}  
 	echo "</table>\n";
?> 

The output of the above appears as below but without any values in the Temperature column:
[text]
Time Temperature
00:00
01:00
02:00
03:00
04:00
05:00
06:00
07:00
08:00
09:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
21:00
22:00
23:00

[/text]

Re: Code doesn't display row[i] values in table??

Posted: Mon Dec 12, 2011 5:19 pm
by jellis00
jellis00 wrote: Can anyone tell me where my code went wrong in doing this??
Found the problem myself. The $row array was empty because I used the wrong field identifier in my original query...should have used 'loginName' and not 'iChipID'. Sorry for the posting.