Jump to content

display records


adzie

Recommended Posts

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>";

}

 

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.