Jump to content

Need help with reducing queries


Zergman

Recommended Posts

So I need to retrieve the totals of certain queries from the same DB table.  Basically need to display the total records for certain conditions.

 

For example, here's part of the queries

$query_rsToday1 = "
SELECT data_id
FROM data
WHERE tdate = '$date' 
AND resolution = 'Resolved'
";
$rsToday1 = mysql_query($query_rsToday1, $cnepix) or die(mysql_error());
$totalRows_rsToday1 = mysql_num_rows($rsToday1);

$query_rsToday2 = "
SELECT data_id
FROM data
WHERE tdate = '$date' 
AND resolution = 'Dispatch'
";
$rsToday2 = mysql_query($query_rsToday2, $cnepix) or die(mysql_error());
$totalRows_rsToday2 = mysql_num_rows($rsToday2);

$query_rsToday3 = "
SELECT data_id
FROM data
WHERE tdate = '$date' 
AND level1 = 'Abandon'
";
$rsToday3 = mysql_query($query_rsToday3, $cnepix) or die(mysql_error());
$totalRows_rsToday3 = mysql_num_rows($rsToday3);

 

I just then display the counts like

<?php echo $totalRows_rsToday1; ?>

 

There has got to be an easier way to condense the queries but I just can't figure it out.

 

Link to comment
Share on other sites

$query = "SELECT data_id, resolution
FROM data
WHERE tdate = '$date' 
AND resolution IN ('Resolved', 'Dispatch')
ORDER BY resolution";

$result = mysql_query($query);
if ($result) {
    $resolved = array();
    $dispatch = array();
    while ($row = mysql_fetch_assoc($result)) {
        if ($row['resolution'] === 'Resolved') {
            $resolved[] = $row;
        } else if ($row['resolution'] === 'Dispatch') {
            $dispatch[] = $row;
        }
    }

    //use $resolved, $dispatch
}

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.