adzie Posted September 24, 2007 Share Posted September 24, 2007 Hi peeps, Just a quick question this is my script so far, I want it to display all the records meeting the criteria specified in the script, but it only shows one records and should show about ten. any thoughts or pointers to get it to display more than one record. many thanks $sql2 = "select * from members where member_id=".$_SESSION[id]; $query2 = mysql_query($sql2); $row3 = mysql_fetch_row($query2); $sql3 = "select * from groups where ID=".$row3['4']; $query3 = mysql_query($sql3); $row4 = mysql_fetch_row($query3); $sql = "select * from cars where group=\"".$row3['4']."\" ORDER BY type, mark, reg ASC"; $query = mysql_query($sql); $result=mysql_query($sql); $number = mysql_numrows($result); for ($i=0; $i<$number; $i++) { $markings = mysql_result($result,$i,"markings"); $type = mysql_result($result,$i,"type"); $mark = mysql_result($result,$i, "mark"); $reg = mysql_result($result,$i, "reg"); } $query_hours = "SELECT sec_to_time(sum(time_to_sec(t2.duration))) AS duration_sum FROM cars t1, members t2 WHERE t1.reg='$reg' AND t1.reg=t2.car"; $result_hours = mysql_query($query_hours); if (mysql_numrows($result_hours) > 0) { $time = mysql_result($result_hours,0,"duration_sum"); } $msg.= "<center><img src=/avatars/".$row4['3']."><br><br><br> <table border=1 align=center><tr><td>Tail</td><td>car</td><td>Mark</td><td>Registration</td><td>Time</td></tr> <tr align=center><td>".$tail."</td><td>".$car."</td><td>".$mark."</td><td>".$reg."</td><td>".$time."</td></tr> </table>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/ Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2007 Share Posted September 24, 2007 I suggest using while ($row = mysql_fetch_array($result)) { instead of using a for loop and mysql_result. Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/#findComment-354086 Share on other sites More sharing options...
adzie Posted September 24, 2007 Author Share Posted September 24, 2007 That was something I tried but I just got timeout errors ?? Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/#findComment-354094 Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2007 Share Posted September 24, 2007 hm, sounds like something is messed up....no idea what, though. Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/#findComment-354096 Share on other sites More sharing options...
macinslaw Posted September 24, 2007 Share Posted September 24, 2007 I'll pipe in, though I'm no expert. It seems you do not have a call to an array. The queries you have bring up only one result for each of your variables, which will display over and over until it reaches the number of the count. You need to have an array and call that array from inside the for/next loop in order to cycle through the results. I would say that you need to make it something like: for ($i=0; $i<$number; $i++) { $row=mysql_fetch_array($result); //Then customize the rest of the script below to reflect the above change $markings = mysql_result($result,$i,"markings"); $type = mysql_result($result,$i,"type"); $mark = mysql_result($result,$i, "mark"); $reg = mysql_result($result,$i, "reg"); } ----OR------ Do the sme thing with a while loop: While (mysql_fetch_row($result)) { $markings = mysql_result($result,$i,"markings"); $type = mysql_result($result,$i,"type"); $mark = mysql_result($result,$i, "mark"); $reg = mysql_result($result,$i, "reg"); } I would use the second, for while I can see what you are trying to do in the for/next loop, I have never used that command before and cannot advise you on how to alter that command, I can only arrive at the same data in a longer method. I hope that helps you. Now if someone would assist me! LOL -Mac Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/#findComment-354100 Share on other sites More sharing options...
adzie Posted September 24, 2007 Author Share Posted September 24, 2007 maybe I should say that I intend to turn the data into a table to update the DB once I can get the information to display correctly Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/#findComment-354130 Share on other sites More sharing options...
adzie Posted September 24, 2007 Author Share Posted September 24, 2007 the end result is a script that will display a list of cars from a group in the format of the above script Quote Link to comment https://forums.phpfreaks.com/topic/70490-display-records/#findComment-354178 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.