Jump to content

Help with multiple table qry


wmguk

Recommended Posts

Hey,

 

i have a script trying to display all the company names in a database.

 

clients (company names)

contacts (actual member of staff)

 

I need to show all companies who uses PAT as account manager...

 

this is my code:

<?
 include ($_SERVER['DOCUMENT_ROOT'] . "/admin/scripts/connection.php");

$sql = "SELECT contacts.a_accmgr, clients.company, clients.level, clients.active FROM clients, contacts 
WHERE contacts.a_accmgr = 'pat' AND (clients.company LIKE '%') AND clients.level != 'CLOSED' AND (clients.level LIKE '%' OR clients.active LIKE '%') 
GROUP BY clients.company 
ORDER BY clients.company ASC " ;

echo $sql;
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) 
{
echo $row['company'];
echo "<br>";
} ?>

 

but currently the results show all businesses in the database, not just where PAT is accmgr.

 

any ideas where my code is wrong?

Link to comment
https://forums.phpfreaks.com/topic/153136-help-with-multiple-table-qry/
Share on other sites

WHERE contacts.a_accmgr = 'pat' AND ...

Does the a_accmgr field in the contacts table limit the clients being returned? I don't believe it would with how you have your query built...

Also, why is there all these "LIKE '%'", that means it could be anything in the field or entirely nothing.

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.