DuaneCawaling Posted March 6, 2013 Share Posted March 6, 2013 (edited) <?php $username = "root"; $password = "vince"; $hostname = "localhost"; $con = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("dummy") or die ("No existing database".mysql_error()); $query = mysql_query("SELECT * from prepurchase"); $row = mysql_fetch_array($query); echo $nrow = mysql_num_rows($query); //=4 while ($row = mysql_fetch_array($query)){ //why does this loop only 3times?? echo $bool = $row['Reply']; echo $id = $row['ID']; $getinfo = mysql_query("SELECT * from profile where studentid = '$id'"); $bal = $getinfo['credit']; $num = $getinfo['contact']; if ($bool == "1") echo "Your order is ready for pickup.<br>"; else if ($bool == "2") echo "Sorry, your order cound not be processed.<br> Your credit is refunded. Remaining credit: $bal.<br>"; } ?> i counted the array, it has 4 items in it..why does it loop only 3 times?? awaw1.bmp Edited March 6, 2013 by DuaneCawaling Quote Link to comment https://forums.phpfreaks.com/topic/275307-understanding-mysql_query/ Share on other sites More sharing options...
AyKay47 Posted March 6, 2013 Share Posted March 6, 2013 The first call to mysql_fetch_array is moving the pointer to the next row. Remove that line and the while loop should work as you expect. Quote Link to comment https://forums.phpfreaks.com/topic/275307-understanding-mysql_query/#findComment-1416900 Share on other sites More sharing options...
Solution DuaneCawaling Posted March 6, 2013 Author Solution Share Posted March 6, 2013 now i get it, thanks for that info it helped my others codes alot! Quote Link to comment https://forums.phpfreaks.com/topic/275307-understanding-mysql_query/#findComment-1417036 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.