Page 1 of 1

Simple "while" loop problem...

Posted: Tue Feb 05, 2008 3:50 pm
by josh27
I have this code...

Code: Select all

<?php 
$link=mysql_connect("localhost","db_test","test"); 
mysql_select_db("table_test",$link); 
 
$sql="SELECT alumno_name, alumno_lastname, alumno_photo FROM Quinto_A_T1_N1"; 
$result=mysql_query($sql); 
$i=0; 
while ($row=mysql_fetch_array($result)) 
{ 
 
echo $row[$i]."<br>"; 
 
}
echo $row[$i]."<br>"; show me only the alumno_photo column, how i can get alumno_name and alumno_lastname, column?...

Re: Simple "while" loop problem...

Posted: Tue Feb 05, 2008 4:23 pm
by Ollie
You're not incrementing $i within the loop, so it's having no effect. But that wont solve your problem!

Rather than echoing $row[$i], I think you want to echo $row['alumno_name'], $row['alumno_lastname'] and $row['alumno_photo'].

The while ($row=mysql_fetch_array($result)) line proceeds through each row returned from the database, returning an array corresponding to that row.