I need help constructing a Query. I think the best way to explain it is to walk through what I need.
First, I need to look in r_agent_cstm
to find the ID number based on the username of the person logged in.
//Find Agent ID
$result1 = mysql_query("SELECT id_c FROM r_agent_cstm WHERE portalusername_c = '$username'");
if (!$result1) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$agent_ID = mysql_fetch_row($result1);
echo $agent_ID[0];
echo "<br />";
Then I need to find any related account IDs for that agent_ID
.
//Find Related Accounts
$result2 = mysql_query("SELECT r_agent_accounts_1accounts_idb FROM r_agent_accounts_1_c WHERE r_agent_accounts_1r_agent_ida = '$agent_ID[0]'");
if (!$result2) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result2)) { echo $row['r_agent_accounts_1accounts_idb']; }
echo "<br />";
Somehow...for each result in step 2 (above), I need to find more account info for the IDs found. (Note: below I set the variable that should be the account ID from step 2, but I didn't know how to pass it with more than one result, so I set it instead just so I could work through the logic on it and test that this was working so far.
$testaccount = "1ec39bf0-5ce9-ea23-d362-54c979b75b0f"; //this should be the result(s) from the previous query.
//Find Related Accounts
$result3 = mysql_query("SELECT companyname_c,status_c FROM accounts_cstm WHERE id_c = '$testaccount'");
if (!$result3) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result3)) { echo $row['companyname_c']; }
echo "<br />";
I need help piecing these queries together in a efficient way that will echo out companyname_c
and status_c
in a tabled format for each result (there may be only 1, none, or there may be hundreds of results).