SF23103 Posted April 27, 2013 Share Posted April 27, 2013 I have a table where I'm trying to display all rows where field5="Brand One". For some reason it's printing the same row over and over instead of the different rows. In other words it's doing this: 1/1/2012 A Bob Smith $3.99 Brand One 1/1/2012 A Bob Smith $3.99 Brand One 1/1/2012 A Bob Smith $3.99 Brand One 1/1/2012 A Bob Smith $3.99 Brand One INSTEAD OF: 1/1/2012 A Bob Smith $3.99 Brand One 1/4/2013 B John Smith $4.99 Brand One 1/7/2013 C Bob Johnson $6.99 Brand One 1/8/2013 Q George Smitherson $8.99 Brand One <?php $username="XXXX"; $password="XXXX"; $database="XXXX"; $servername="XXXX"; mysql_connect($servername,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT * FROM `list` WHERE Field5 = 'brand one'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> Brand One: <table> <?php $i=0; while ($i < $num) { $list_result1=mysql_result($result,0,"field1"); //Date $list_result2=mysql_result($result,0,"field2"); //Letter $list_result3=mysql_result($result,0,"field3"); //Name $list_result4=mysql_result($result,0,"field4"); //Price $list_result5=mysql_result($result,0,"field5"); //Brand ?> <tr><td><?php echo $list_result1; ?></td><td><?php echo $list_result2; ?></td><td><?php echo $list_result3; ?></td><td><?php echo $list_result4; ?></td><td><?php echo $list_result5; ?></td></tr> <?php $i++; } ?> </table> Any ideas?? :-) Quote Link to comment Share on other sites More sharing options...
trq Posted April 27, 2013 Share Posted April 27, 2013 The second argument to mysql_result is the row. Your giving it 0 over and over again. Your not using $i anywhere. Having said that, why are you using mysql_result at all? The documentation clearly states: you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). On top of that, the mysql extension has been deprecated. Any new code should be written using PDO or MySQLi instead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.