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

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.