calmchess Posted May 18, 2013 Share Posted May 18, 2013 Why is this mysql query only returning the last row of data? I can't remember how to write this correctly. Please help. <?php session_start();$docID=7768;if($docID===7768){__putreg($docID);}function __putreg($docID){if($docID===7768){ //check database for credentials $conn0=mysqli_connect("localhost","calmchess","ptoK4ptoK4","book");if($conn0){$q0=mysqli_query($conn0,"select _logged_in_picpath,_logged_in_username from logged_in_users")or die(mysqli_error($conn0));while($row = mysqli_fetch_array($q0)){$picpaths0[]=$row['_logged_in_picpath'];$usernames0[]=$row['_logged_in_username'];} for($i=0;$i<count($picpaths0);$i++){$picspaths00 = $picpaths0[$i].":::";$picassets0=$picspaths00."^^^".$usernames0[$i];if($i/4==0){$picassets0=$picassets0."xxx";}if($i==count($picpaths0)-1){ echo $picassets0;}}} }} ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 18, 2013 Share Posted May 18, 2013 Because you're only echoing it once, after everything is done. You have two loops, you only need one, and you should echo within the loop. Quote Link to comment Share on other sites More sharing options...
Solution calmchess Posted May 18, 2013 Author Solution Share Posted May 18, 2013 yeah you are correct Here How I solved it <?php session_start(); $docID=7768; if($docID===7768){__putreg($docID);} function __putreg($docID){ if($docID===7768){ //check database for credentials $conn0=mysqli_connect("localhost","calmchess","ptoK4ptoK4","book"); if($conn0){ $q0=mysqli_query($conn0,"select _logged_in_picpath,_logged_in_username from logged_in_users")or die(mysqli_error($conn0)); $j=-1; while($row = mysqli_fetch_array($q0)){ $j++; $picpaths0[]=$row['_logged_in_picpath']; $usernames0[]=$row['_logged_in_username']; $picspaths00 = $picpaths0[$j].":::"; $picassets0=$picspaths00."^^^".$usernames0[$j]; if($j/4==0){ $picassets0=$picassets0."xxx"; } echo $picassets0; } } } } ?> 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.