Crew-Portal Posted November 11, 2007 Share Posted November 11, 2007 <?php while ($row = mysql_fetch_array($result)) { $active = $row['active']; /**/ # Hours /**/ $query = "SELECT sum(hours) FROM flights WHERE user_id = $row[user_id]"; /**/ $result=mysql_query($query); /**/ $blcktime = number_format(mysql_result($result,0)); /**/ $query = "SELECT sum(minutes) FROM flights WHERE user_id = $row[user_id]"; /**/ $result=mysql_query($query); /**/ $blckmins = number_format(mysql_result($result,0)); $intSeconds = ($blcktime*3600)+($blckmins*60); $sqlname = "SELECT air_id FROM user WHERE user_id = $row[user_id]"; $resultname = @mysql_query($sqlname,$connection) or die("Ouch! Invalid Charactor On ID Field! You may Only Put Numbers On The ID Field"); $numname=mysql_num_rows($resultname); while ($rowname = mysql_fetch_array($resultname)) { $username = $rowname['username']; $airline_identnum = $rowname['air_id']; } $sqlname = "SELECT name,short FROM airlines WHERE air_id = $airline_identnum"; $resultname = @mysql_query($sqlname,$connection) or die("Ouch! Invalid Charactor On ID Field! You may Only Put Numbers On The ID Field"); $numname=mysql_num_rows($resultname); while ($rowname = mysql_fetch_array($resultname)) { $airline = $rowname['name']; $short = $rowname['short']; } ?> Okay this code works fine except its only pulling the first record in the database But when I remove the lines: <?php /**/ # Hours /**/ $query = "SELECT sum(hours) FROM flights WHERE user_id = $row[user_id]"; /**/ $result=mysql_query($query); /**/ $blcktime = number_format(mysql_result($result,0)); /**/ $query = "SELECT sum(minutes) FROM flights WHERE user_id = $row[user_id]"; /**/ $result=mysql_query($query); /**/ $blckmins = number_format(mysql_result($result,0)); /**/ $intSeconds = ($blcktime*3600)+($blckmins*60); ?> Then all of a sudden it works and it pulls all of the records again. So the error is in the line of code right ^^^ So if anyone could help. Link to where this is right here http://24.76.166.219/index.php?page=roster Link to comment https://forums.phpfreaks.com/topic/76821-its-only-selecting-one-record/ Share on other sites More sharing options...
cooldude832 Posted November 11, 2007 Share Posted November 11, 2007 by repeating the use of $result it destroys that mysql resource, thus when it finnishes one itteration of the loop the $result has changed and no longer fetches the next item to the array beraking the loop, so use different names for your mysql queries, but your code looks really bloated try combining that into like a few less queries cause it probably takes forver to load Link to comment https://forums.phpfreaks.com/topic/76821-its-only-selecting-one-record/#findComment-388934 Share on other sites More sharing options...
Crew-Portal Posted November 11, 2007 Author Share Posted November 11, 2007 So could you fix my code and resend it because im not exactly sure what you mean? Link to comment https://forums.phpfreaks.com/topic/76821-its-only-selecting-one-record/#findComment-388939 Share on other sites More sharing options...
trq Posted November 11, 2007 Share Posted November 11, 2007 Here.... while ($row = mysql_fetch_array($result)) { you create a loop. Within this same loop however you are again using the variable $result. Logic shows that this will not work as expected. Link to comment https://forums.phpfreaks.com/topic/76821-its-only-selecting-one-record/#findComment-388940 Share on other sites More sharing options...
cooldude832 Posted November 11, 2007 Share Posted November 11, 2007 So could you fix my code and resend it because im not exactly sure what you mean? No I will not do your work for you, just change the repeated use of the word $result in the loop and it will fix itself Link to comment https://forums.phpfreaks.com/topic/76821-its-only-selecting-one-record/#findComment-389149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.