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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.