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]

Link to comment
Share on other sites

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

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.