How to I count how many times particular location is selected?

I am trying to developing booking management,in which I can able to book 4 books for particular day per one location . for that I have developed on.

static function check_total_appointment() 
{
   global $birchschedule;
   global $wpdb;

    $qry = "SELECT meta_value FROM postmeta WHERE meta_key='_birs_appointment_location'";
    $states = $wpdb->get_results( $qry );


 pr($_POST['birs_appointment_location']);
    $querystr = "
    SELECT meta_value from $wpdb->postmeta
    WHERE meta_key = '_birs_appointment_timestamp'";

 $Locations = "
    SELECT meta_value from $wpdb->postmeta
    WHERE meta_key = '_birs_appointment_location'";

    $pageposts = $wpdb->get_results($querystr, OBJECT);
    // pr($pageposts);
    $location_id = $wpdb->get_results($Locations, OBJECT);
    // pr($location_id);
    $count = 1;
$L_count=1;
 foreach ($location_id as $LocationId) 
    {
        // pr($LocationId);
        if($_POST['birs_appointment_location'] == $LocationId->meta_value)
        $L_count++;
    }

echo "string".$L_count;

    foreach ($pageposts as $value) 
    {
      //  pr(gmdate("m/d/Y", $value->meta_value));
        if(trim($_POST['birs_appointment_date'])==trim(gmdate("m/d/Y", $value->meta_value)))
        {
            $count++;

        }

    }
echo "check".$count;
    if ($count>4 && $L_count>4)
    {
         return 1;
    }
}

I got count but problem is I got same count number in another location ,means suppose I have booked on book in particular location then count of this location is two now and count of another location is one but I got same count number in another location means two,now suppose I have booked book in location two so now I count number three for all location .

Related posts

Leave a Reply