sac8513
01-13-2007, 04:30 PM
I have been working on developing code that analyzes a database in mySQL to search for a stores name, when it opens and when it closes.
The php code that I am using also is set to the server time to outut whether that particular store is open or closed. My issue is that I now need to add each day of the week to the code to make it work properly. Any ideas?
Here is what I currently have
$query="SELECT * FROM timetest ORDER BY store_name ASC";
$result=mysql_query($query);
$num=mysql_numrows($result) or die('There are currently no stores in our database.');
echo '<table border="0" cellspacing="4" cellpadding="4" colspan"140">
<tr>
<th><font face="Arial, Helvetica, sans-serif"></font></th>
<th><font face="Arial, Helvetica, sans-serif">Telephone</font></th>
<th style="white-space: nowrap;"><font face="Arial, Helvetica, sans-serif">Hours of Operation</font></th>';
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"store_name");
$tele=mysql_result($result,$i,"telephone");
$o=mysql_result($result,$i,"open_time");
$c=mysql_result($result,$i,"close_time");
$op = split(':',$o);
$open = ($op[0]*60)+$op[1];
$cl = split(':',$c);
$close = ($cl[0]*60)+$cl[1];
$sign = "-";
$h = "5";
$dst = "true";
if ($dst) {
$daylight_saving = date('I');
if ($daylight_saving){
if ($sign == "-"){ $h=$h-1; }
else { $h=$h+1; }
}
}
$hm = $h * 60;
$ms = $hm * 60;
if ($sign == "-"){ $timestamp = time()-($ms); }
else { $timestamp = time()+($ms); }
$hour = gmdate("H", $timestamp);
$minutes= gmdate("i", $timestamp);
$now = ($hour*60)+$minutes;
echo '<tr>
<td><font face="Arial, Helvetica, sans-serif"><a href='.$name.'.html>'.$name.'</a></font></td>
<td style="white-space: nowrap;"><font face="Arial, Helvetica, sans-serif">'.$tele.'</font></td>
<td><font face="Arial, Helvetica, sans-serif">';
if(($now>=$open)&&($now<$close))
echo 'Open';
else
echo 'Closed';
echo '</font></td></tr>';
$i++;
}
echo '</table>';
mysql_close();
?>
The php code that I am using also is set to the server time to outut whether that particular store is open or closed. My issue is that I now need to add each day of the week to the code to make it work properly. Any ideas?
Here is what I currently have
$query="SELECT * FROM timetest ORDER BY store_name ASC";
$result=mysql_query($query);
$num=mysql_numrows($result) or die('There are currently no stores in our database.');
echo '<table border="0" cellspacing="4" cellpadding="4" colspan"140">
<tr>
<th><font face="Arial, Helvetica, sans-serif"></font></th>
<th><font face="Arial, Helvetica, sans-serif">Telephone</font></th>
<th style="white-space: nowrap;"><font face="Arial, Helvetica, sans-serif">Hours of Operation</font></th>';
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"store_name");
$tele=mysql_result($result,$i,"telephone");
$o=mysql_result($result,$i,"open_time");
$c=mysql_result($result,$i,"close_time");
$op = split(':',$o);
$open = ($op[0]*60)+$op[1];
$cl = split(':',$c);
$close = ($cl[0]*60)+$cl[1];
$sign = "-";
$h = "5";
$dst = "true";
if ($dst) {
$daylight_saving = date('I');
if ($daylight_saving){
if ($sign == "-"){ $h=$h-1; }
else { $h=$h+1; }
}
}
$hm = $h * 60;
$ms = $hm * 60;
if ($sign == "-"){ $timestamp = time()-($ms); }
else { $timestamp = time()+($ms); }
$hour = gmdate("H", $timestamp);
$minutes= gmdate("i", $timestamp);
$now = ($hour*60)+$minutes;
echo '<tr>
<td><font face="Arial, Helvetica, sans-serif"><a href='.$name.'.html>'.$name.'</a></font></td>
<td style="white-space: nowrap;"><font face="Arial, Helvetica, sans-serif">'.$tele.'</font></td>
<td><font face="Arial, Helvetica, sans-serif">';
if(($now>=$open)&&($now<$close))
echo 'Open';
else
echo 'Closed';
echo '</font></td></tr>';
$i++;
}
echo '</table>';
mysql_close();
?>