Jump to content

Recommended Posts

here is the query:

 

$result = t_day, count(t_id) AS t_daycount FROM tickets WHERE t_company = '".$_SESSION['company']."' AND t_day BETWEEN Date1 AND Date2 Group By t_day

 

As of right now, I have 2 rows

 

t_day            t_daycount

Mon                      2

Wed                      1

 

 

What I want to do, is get vars for each day of the week, regardless if there are rows and set them to the day

 

so...

$mon = 2

$tue = 0  (no record)

$wed = 1

etc..

easiest thing to do would be to have a row for each day with a default value of 0 and have all of them returned.

 

next easiest thing to do would be to hardcode them

 

$mon = 0; $tue = 0; etc... before the query and overwrite the ones returned.

 

 

okay so you run your query and the results are returned in $result.  So next you would set a default value of 0 for each variable, then you loop through $result, and in the loop, you would overwrite the variables that are in the table.  So for instance your example has mon | 2 and wed | 1, so...

$sun = 0; $mon = 0; $tue = 0; $wed = 0; $thu = 0; $fri = 0; $sat = 0;
while ($list = mysql_fetch_assoc($result)) {
  $$list['t_day'] = $list['t_daycount'];
}
echo $sun . "<br/>";
echo $mon . "<br/>";
echo $tue . "<br/>";
echo $wed . "<br/>";
echo $thu . "<br/>";
echo $fri . "<br/>";
echo $sat . "<br/>";

 

That would output

0

2

0

1

0

0

0

 

 

 

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.