Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 23 September 2006 - 07:54 PM

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

<?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>';
  }
?>

any suggestions?

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 23 September 2006 - 08:22 PM

Before the loop, add- $i=1.
And instead of writing $i=NULL (in the end of the loop), write $i=1.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 23 September 2006 - 08:26 PM

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

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 23 September 2006 - 08:28 PM

That's probbly because $libmysql->fetch_array() doesnt move the internal pointer.
Why dont you use mysql_fetch_array($query) ?

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 23 September 2006 - 08:29 PM

i did, same effect. $libmysql->fetch_array is just a function i defined.

#6 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 23 September 2006 - 08:48 PM

ok got it working thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users