asmith Posted December 1, 2007 Share Posted December 1, 2007 <?php $conn = mysql_connect("localhost","john","abc"); mysql_select_db("test",$conn); $sql = "select * from aaa where name = 'test1'"; $re = mysql_query($sql,$conn); $list = mysql_fetch_array($re); $text = implode ("<br />",$list); echo $text; ?> i have 10 fileds in mysql which name = test1 . when i type "select * from aaa where name=test 1" in mysql command, it shows me all the 10 resault but when i do the above code, it shows me only the first row in that table, and it echo each value of the field 2 times ! like 1 1 asd asd john john what is wrong about that ? how can i get all the rows ? Quote Link to comment Share on other sites More sharing options...
asmith Posted December 1, 2007 Author Share Posted December 1, 2007 oh i meant 10 rows, there are 10 rows that name='test1' Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted December 1, 2007 Share Posted December 1, 2007 so what you want it to do show all records in the db ? or just a certin one? Quote Link to comment Share on other sites More sharing options...
asmith Posted December 1, 2007 Author Share Posted December 1, 2007 i wanna show all which the name=test1 . there are about 10 rows in fact , i can do that but in other ways, i'm just so curious why this line in sql shows right, but in php mixed up things, it is something about mysql_fetch_array i guess Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 print_r($re) to see what your array contains. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 1, 2007 Share Posted December 1, 2007 Each call to a mysql_fetch_xxxxx() function only fetches one row from a result set, like the php manual states. To fetch all rows from a result set, you would need to use something like a while() loop to iterate over the result set, like the mysql examples in the php manual. 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.