rabmerab Posted May 2, 2008 Share Posted May 2, 2008 Hi every one, May be this is a just a basic but I am stuck. I am using the sql query $sql="select * from mytable " to try to display 4 rows but I getting only one. when I am using mysql command line with the same query I get all the 4 rows. the problem only in php. The other things like connecting to mysql and selecting the database been done. Any help please. Thanks in advance. Rabmerab Screen shot: #connect to my sql $conn=@mysql_connect("localhost","me","mypass") or die ("Couldn't connect"); # select database $rs=@mysql_select_db("mydatabase",$conn)or die("could not select database"); #Create the sql query $sql="select * from mytable "; # Execute query $rs= mysql_query($sql,$conn); #get the number of rows $num=mysql_numrows($rs); while($row= Mysql_fetch_array($rs) ) { $list="<br>".$row["imei"]; echo($list); } ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted May 2, 2008 Share Posted May 2, 2008 You have list =, not list .= -- you're replacing it, and only getting the last row's value. Quote Link to comment Share on other sites More sharing options...
rabmerab Posted May 2, 2008 Author Share Posted May 2, 2008 Hi there, Thanks for replaying. Is not that the problem; in the program above, using $num=mysql_numrows($rs) to count number of rows should deliver 4, even if I add more rows always echo($num) only show 1. Any more ideas. rabmerab Quote Link to comment Share on other sites More sharing options...
fenway Posted May 2, 2008 Share Posted May 2, 2008 That seems impossible... wait, it's it mysql_num_rows()? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 Yeah, it should be erroring out at mysql_numrows...do you have error reporting turned on? Quote Link to comment Share on other sites More sharing options...
rabmerab Posted May 2, 2008 Author Share Posted May 2, 2008 Hi again, I don't know how come it didn't display the error even i got display_errors in phpinfo shows it is on. It did shows me other errors. Any way even I change it to $num=mysql_num_rows($rs), now it shows 2 but in reality, the table has 6 rows. I don't know what's going on. thanks for any more help. rabmerab Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 2, 2008 Share Posted May 2, 2008 rahmerab: Paste your real actual code here please. Everyone is guessing, because you're not providing the information we need. Quote Link to comment Share on other sites More sharing options...
fenway Posted May 2, 2008 Share Posted May 2, 2008 I don't know what's going on. Neither do any of us... turn on error reporting, and as gizmola said, let's make sure we're talking about the same code here. 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.