Hi All,
Im running a script that goes 3 deep on parentheses, and then needs to change database at the deepest level.
Im having trouble switching to that database in an if else query.
any help would be appreciated
function getElement1(){
$con = mysql_connect('localhost','uname','pword') or die (mysql_error());
$authenticate = mysql_select_db('authenticate');
$today = date("Y-m-d");
$SQL = "SELECT campaign, agent, SUM(duration), firstname, lastname
FROM rota_element
JOIN people on agent= user_id
WHERE date = '$today'
AND rota_element.active ='Yes'
AND campaign NOT IN('BCC', 'Holiday')
GROUP BY agent";
$result = mysql_query($SQL) or die (mysql_error());
echo "<table border=\"1\">
<tr><th>First Name</th>
<th>Surname</th>
<th>Rota Hours</th>
<th>Volume Target</th>
<th>Acheived</th>
<th>Status</th></tr>
";
while ($row = mysql_fetch_array($result)){
$agent = $row['agent'];
$campaign = $row['campaign'];
echo "<tr><td>" . $row['firstname'] . '</td><td>' . $row['lastname'] . '</td><td>' . $row['SUM(duration)'] . "</td></tr>";
$SQL2 = "SELECT distinct(campaign) FROM rota_element WHERE agent = '$agent' AND date = '$today' AND campaign NOT IN ('BCC', 'Holiday') AND active = 'Yes'";
$results = mysql_query($SQL2) or die(mysql_error());
while ($row = mysql_fetch_array($results)){
$campaign = $row['campaign'];
echo "<tr><td></td><td>" . $row['campaign'] . "</td>";
$SQL3 = "SELECT SUM(duration), agent FROM rota_element WHERE agent = '$agent' AND date = '$today' AND campaign = '$campaign' and active = 'yes' group by campaign";
$results3 = mysql_query($SQL3) or die(mysql_error());
while ($row = mysql_fetch_array($results3)){
echo "<td>" . $row['SUM(duration)'] . "</td>";
$user_id = $row['agent'];
$SQL4 = "SELECT agentid FROM people WHERE user_id = '$agent'";
$results4 = mysql_query($SQL4) or die(mysql_error());
$row = mysql_fetch_assoc($results4);
$user_id = $row['agentid'];
if ($campaign == 'one'){
mysql_select_db('one');
$SQL5 = "SELECT COUNT(*) FROM one.accounts WHERE agentid = '$user_id' AND status = 'COMPLETED' and DATE(timestamp_dtm) = '$today'";
$results5 = mysql_query($SQL5) or die (mysql_error());
$row = mysql_fetch_assoc($results5);
$completed = $row['COUNT(*)'];
echo "<td>" . $completed . "</td>";
}
//once i get here it wont switch databases. It stops showoing all results
}
}
}
}