Jump to content

[SOLVED] Setting variables based on db value


coupe-r

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

 

 

 

Archived

This topic is now archived and is closed to further replies.

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