Jump to content

Archived

This topic is now archived and is closed to further replies.

newb

while loop not echo'ing multiple results(repeating itself)

Recommended Posts

im having a bit of trouple with the while loop...its probably an easy fix, just cant figure it out atm.

[code]
<?php
$query = $libmysql->query("SELECT * from $table_users ORDER by username ASC");
echo "<table width='100%' align='center'>
  <tr>
    <td colspan='4' valign='top' id='navcontent'>$links</td>
  </tr>
  <tr>
    <td colspan='4' valign='top'><strong>Member List </strong></td>
  </tr>
  <tr>
    <td valign='top'><strong>Name</strong></td>
    <td valign='top'><strong>Usergroup</strong></td>
    <td valign='top'><strong>Registration Date </strong></td>
    <td valign='top'><strong>Email</strong></td>
  </tr>";
while ($row = $libmysql->fetch_array($query)) {
$i++;
$user = $row['username'];
$signup_date = $row['signup_date'];
$email = $row['email'];
$tempsid = $row['sid'];
$query = $libmysql->query("SELECT * FROM $table_usergroups WHERE id = '$tempsid'");
$row = $libmysql->fetch_array($query);
$custom_title = $row['custom_title'];
$libmysql->free_result($query);
echo "<tr>
<td width='35%' valign='top'>$user</td>
<td width='60%' valign='top'>$custom_title</td>
<td width='60%' valign='top'>$signup_date</td>
<td width='60%' valign='top'>$email</td>
  </tr>";
 
  if ( $i == 2 ) {
  echo "<tr><td width='35%' valign='top'>$user</td>
<td width='60%' valign='top'>$custom_title</td>
<td width='60%' valign='top'>$signup_date</td>
<td width='60%' valign='top'>$email</td>";
  $i = NULL;
}

echo '</tr></table>';
  }
?>[/code]

any suggestions?

Share this post


Link to post
Share on other sites
Before the loop, add- $i=1.
And instead of writing $i=NULL (in the end of the loop), write $i=1.

Orio.

Share this post


Link to post
Share on other sites
ok it echo's multiple tables but in each of the tables it repeats the same information....ie:

John Doe - john@doe.com
John Doe - john@doe.com

instead of :
John Doe - john@doe.com
Other John Doe - otherjohn@doe.com

Share this post


Link to post
Share on other sites
That's probbly because $libmysql->fetch_array() doesnt move the internal pointer.
Why dont you use mysql_fetch_array($query) ?

Orio.

Share this post


Link to post
Share on other sites
i did, same effect. $libmysql->fetch_array is just a function i defined.

Share this post


Link to post
Share on other sites

×

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.