Jump to content

Query results are 2 of each...


NathanLedet

Recommended Posts

this just crept up on me and I'm completely puzzled as to why it's happening.

 

Login page logs you in, and then on to the Admin features:

 

<?php  
session_start();
include('includes/mysql_connect.php'); 

$query2 = 'SELECT userID FROM users WHERE username = "' . $_SESSION['MM_Username'] . '"';
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)){
$userID =  $row2['userID'];
}

$query  = "SELECT users.userID, users.username, addressbook.userID, addressbook.name, addressbook.email, addressbook.emailID";
$query .= " FROM users, addressbook";
$query .= " WHERE addressbook.userID = \"" . $userID . "\"";
$query .= " ORDER BY addressbook.name ASC";
$result = mysql_query($query);

echo "<table width=\"500px\" border=\"0\">\r
<tr>\r
  <td width=\"25%\">Name</td>\r
  <td width=\"60%\">E-mail Address</td>\r
  <td width=\"15%\">Options</td>\r
</tr>\r 	</table>";
echo "<div style=\"width:500px; height:225px; overflow:auto;\">";
echo "<table width=\"500px\" border=\"0\" id=\"addressbook\">\r";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo "<tr>
   <td width=\"25%\" class=\"tbldata\">{$row['name']}</td>
   <td width=\"60%\" class=\"tbldata\">{$row['email']}</td>
   <td width=\"15%\" class=\"tbldata\"><a href=\"/addressbook_update.php?emailID={$row['emailID']}\">Edit</a> / <a href=\"/addressbook_delete.php?emailID={$row['emailID']}\">Delete</a></td>
</tr>\r";
}
echo "</table>\r</div>";
?>

 

It works (it's also a sloppy way of doing it, I realize this, but I'm a newbie just trying to get it to work first ;) ), but the results of the query displays each item twice.

Link to comment
https://forums.phpfreaks.com/topic/114612-query-results-are-2-of-each/
Share on other sites

I think the problem is with your query string.  You're selecting data from two different tables but your where clause only restricts one of them.  I think you're going to need to add a JOIN in there somewhere.  I think.  I'm really not that great at query strings.  But I'm pretty sure it's your actual query string.  I can move this over to the sql forum if you want...

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.