wmguk Posted April 8, 2009 Share Posted April 8, 2009 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 More sharing options...
Brian W Posted April 8, 2009 Share Posted April 8, 2009 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. Link to comment https://forums.phpfreaks.com/topic/153136-help-with-multiple-table-qry/#findComment-804629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.