Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- URGENT help with SQL statements


Demaestro - 4:09 pm on Sep 30, 2011 (gmt 0)


Hi Max,

You may want to do this with an SQL statement, then a loop with another SQL statement in it.

Something like this:

$agency_sql = 'select agent_id, agent_name from agency_table';
$agency_data = execute_sql($agency_sql);

for($i=0; $i<count($agency_data); $i=$i+1) {

$row = $agency_data[$i];

client_sql = 'select count(client_id) as client_count from client_table where agent_id = ' . $row['agent_id'];

client_data = execute_sql($agency_sql);

echo $row['agent_name'] . ' ' . client_data[0]['client_count'] . '<br /'>;

}


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4369171.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com