coupe-r Posted June 11, 2009 Share Posted June 11, 2009 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.. Link to comment https://forums.phpfreaks.com/topic/161764-solved-setting-variables-based-on-db-value/ Share on other sites More sharing options...
.josh Posted June 11, 2009 Share Posted June 11, 2009 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. Link to comment https://forums.phpfreaks.com/topic/161764-solved-setting-variables-based-on-db-value/#findComment-853545 Share on other sites More sharing options...
coupe-r Posted June 11, 2009 Author Share Posted June 11, 2009 Thank you.... But how do I write php so that after the query and all the days are set to 0, how would php know that row[0] will become there own variables? and row[1] are the values? Link to comment https://forums.phpfreaks.com/topic/161764-solved-setting-variables-based-on-db-value/#findComment-853547 Share on other sites More sharing options...
.josh Posted June 11, 2009 Share Posted June 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/161764-solved-setting-variables-based-on-db-value/#findComment-853560 Share on other sites More sharing options...
coupe-r Posted June 11, 2009 Author Share Posted June 11, 2009 I cannot thank you guys here enough. You always give excellent help. Thanks again. Link to comment https://forums.phpfreaks.com/topic/161764-solved-setting-variables-based-on-db-value/#findComment-853850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.