Bas D L Posted September 5, 2012 Share Posted September 5, 2012 Hi, I am a newbie and i have a question: I have made a while loop that puts status on free, occupied or option. The question is if i for example dates 3-10 4-10 5-10 6-10, want to set 3-10 start.gif and 6-10 end.gif and ofcourse the 4-10 5-10 occupied? Kind regards! The script: mysql: public function getDataStatusByAcconr($acconr,$year,$month) { $query = mysql_query("SELECT calender.day as day, calender.status as status FROM `calender` left join accos on calender.acco_id = accos.acco_id where accos.acconr = '$acconr' and calender.year = '$year' and calender.month = '$month' order by calender.day"); $result2 = array(); while ($array = mysql_fetch_array($query, MYSQL_ASSOC)) { $result2[] = $array; } return $result2; } While loop: while ( $day_num <= $days_in_month ) { $objViewAdmin = new Model(); $resultset = array(); $resultset = $objViewAdmin->getDataStatusByAcconr($acconr,$year,$month); $days = ''; $status = ''; foreach ($resultset as $value){ if($day_num == $value['day']){ $days .= $value['day'].','.$value['status'].'|'; } } echo '<pre>'.print_r($days,true).'</pre>'; if (preg_match("/$day_num\,/", "$days|")) { if (preg_match("/\,0/", "$days|")) { echo "<td style=\"background-image:url('images/free.jpg');\"> <a href=\"$day_num\">$day_num</a> </td>"; } if (preg_match("/\,1/", "$days|")) { echo "<td style=\"background-image:url('images/occupied.jpg');\"> $day_num </td>"; } if (preg_match("/\,3/", "$days|")) { echo "<td style=\"background-image:url('images/option.jpg');\"> <a href=\"$day_num\">$day_num</a> </td>"; } } else{ echo "<td style=\"background-color:";echo "#008000"; echo "\"> $day_num </td>"; } $day_num++; $day_count++; if ($day_count > 7){ echo "</tr><tr>"; $day_count = 1; } } Link to comment https://forums.phpfreaks.com/topic/268008-calendar-start-end/ Share on other sites More sharing options...
memfiss Posted September 5, 2012 Share Posted September 5, 2012 " $result2 = array(); while ($array = mysql_fetch_array($query, MYSQL_ASSOC)) { $result2[] = $array; } " u dont need second variable $result2 = array(); while ($result2[] = mysql_fetch_array($query, MYSQL_ASSOC)); "want to set 3-10 start.gif and 6-10 end.gif " u can made some config , like $img_conf ['3-10'] = 'start.gif' and then call it $img = isset($img_conf [$variable]) ? $img_conf [$variable] : null; Link to comment https://forums.phpfreaks.com/topic/268008-calendar-start-end/#findComment-1375388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.