0

Hey, I'm working on a project and require some help. I have two tables in the same database and I want to query each table using the ID just using one query. It works but it displays the same information more than once even though there is only one entry. For example:

Phillip
Phillip
Phillip
Name
Name
Name
Smith
Smith
Smith

<?php

  function connect()
  {
     $dbh=mysql_connect ("localhost", "root", "root");
     mysql_select_db("game");
  }
  
  connect();
  
  $q = "SELECT user.title AS user_title, moderators.title AS sub_title FROM users, moderators WHERE user.title = moderators.title GROUP BY moderators.title";
  $r = mysql_query($q);
  if(mysql_affected_rows() >= 1)
  {
    
   while ($row = mysql_fetch_array($r))
   {
      echo $row['user_title'];
   
   }
  }else{
    echo 'not ok';
  }
  
?>

Any help please?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Encrypted
0

I'm not 100% sure, because I almost always use mysql_fetch_assoc, but I think you're missing a second parameter in your mysql_fetch function:

Edit: Just looked at some other threads and apparently you don't need it, so disregard this post.

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

Source: http://www.php.net/manual/en/function.mysql-fetch-array.php

Edited by Encrypted: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.