Jump to content

[SOLVED] SQL query results in 10x duplicate results.


drummer101

Recommended Posts

[code]<?php $result=mysql_query("SELECT phpbb_user_group.user_id, phpbb_users.username, profile.rlname, 
profile.name, profile.primary_class, profile.secondary_class FROM phpbb_user_group, phpbb_users, 
profile WHERE phpbb_user_group.group_id = 6 AND phpbb_users.user_id = phpbb_user_group.user_id ORDER BY profile.name ASC");
echo "<table width=\"451\" height=\"50\" border=\"1\">
    <tr>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Handle</div></td>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Name</div></td>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Primary</div></td>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Secondary</div></td>
    </tr>";
while ($i = mysql_fetch_array($result)){
		echo "<tr>
        	<td><a href='images/profile.jpg' rel=\"lightbox\" title=\"{$i['username']}\">{$i['username']}</a></td>
		<td>{$i['rlname']}</td>
		<td>{$i['primary_class']}</td>
		<td>{$i['secondary_class']}</td>";
}
echo "</table>";
//echo "<p><a href='images/profile.jpg' rel=\"lightbox\" title=\"{$i['username']}\">{$i['username']}</a></p>";
}?>

 

phpbb_username and profile_name are identical fields.

 

The one problem I'm having with this is that when the page loads, theres 10 iterations of everyone's name.

What did I miss/mess up to make it do that?[/code]

The only way I can think of getting around the problem is something like,

<?php$result=mysql_query("SELECT phpbb_user_group.user_id, phpbb_users.username FROM phpbb_user_group, phpbb_users WHERE phpbb_user_group.group_id = 6 AND phpbb_users.user_id = phpbb_user_group.user_id ORDER BY `username` ASC");
echo "<table width=\"451\" height=\"50\" border=\"1\">
    <tr>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Handle</div></td>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Name</div></td>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Primary</div></td>
    <td class=\"\" align=\"center\"><div class=\"tblheader\">Secondary</div></td>
    </tr>";
while ($i = mysql_fetch_array($result)){
$result2=mysql_query("SELECT profile.name, profile.rlname, profile.primary_class, profile.secondary_class FROM profile WHERE profile.name = {$i['username']}");
	while ($I = mysql_fetch_array($result2)){
		echo "<tr>
        	<td><a href='images/profile.jpg' rel=\"lightbox\" title=\"{$i['username']}\">{$i['username']}</a></td>
		<td></td>
		<td> </td>
		<td> </td>
		</tr>";
}
}
echo "</table>";?>

 

The question there though is, is it legal to use the result of an array variable in a SQL query?

<?php $result2=mysql_query("SELECT profile.name, profile.rlname, profile.primary_class, profile.secondary_class FROM profile WHERE profile.name = {$i['username']}");?>

Archived

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

×
×
  • 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.