使用HTML / PHP存储时间(句点)(特定小时)(持续时间) - 天/小时

时间:2015-05-11 14:17:55

标签: php html mysql sql google-maps

我一直在处理一个页面,该页面使用html和php存储一周中的几天开放时间到数据库。为了使用数据条目将其与当前时间进行比较..我尽了最大努力,但它不起作用。我要告诉你html,php,sql代码,这样你就可以告诉我如何解决它。

HTML + CSS表单代码:

http://jsfiddle.net/Naz970/4y4sd91u/

SQL:

CREATE TABLE IF NOT EXISTS `markers` (
`id` int(11) NOT NULL,
  `name` varchar(60) NOT NULL,
  `phone` int(100) NOT NULL,
  `address` varchar(80) NOT NULL,
  `email` varchar(100) NOT NULL,
  `link` varchar(200) NOT NULL,
  `lat` float(10,6) NOT NULL,
  `lng` float(10,6) NOT NULL,
  `type` varchar(30) NOT NULL,
  `days` varchar(100) CHARACTER SET utf8 NOT NULL,
  `openingHours` varchar(255) NOT NULL,
  `img` blob NOT NULL
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=51

PHP代码:

<?php
    include ("../Connections/Connection.php");



    if (isset($_POST["submit"])) {
        $name = $_POST["name"];
        $type = $_POST["type"];
        $address = $_POST["address"];
        $email = $_POST["email"];
        $phone = $_POST["phone"];
        $link = $_POST["link"];
        $lng = $_POST["lng"];
        $lat = $_POST["lat"];
        $days = implode(";", $_POST['days']);
        $openingHours = implode(";", $_POST['openingHours']);
        $img = time().$_FILES['photo']['name'];
        if (!move_uploaded_file($_FILES['photo']['tmp_name'],'../Uploads/'.$img))  die("error");

         $sql = "INSERT INTO markers (name,  type, address, email, phone, link, lng, lat, days, openingHours, img)
         VALUES('$name', '$type', '$address', '$email', '$phone', '$link', '$lng', '$lat', '$days', '$openingHours', '$img')";

         $query = mysql_query($sql);

         if (!$query) {
                die("Error : " . mysql_error());
            }
         if (empty($name) || empty($type) || empty($address) || empty($email) || empty($phone) || empty($lng) || empty($lat) || empty($days) || empty($openingHours) || empty($img)) {
         echo "You did not fill out the required fields.";
                die();  // Note this
            }
       echo "<center></center>";
        }


        ?>

但是表单(时间表(日程表))不起作用而且没有正确存储数据。我用它来做以下事情:

标记比较的PHP代码

<?php
require("config.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&apos;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a mySQL server
$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE

    $days = explode(";", $row['days']);
  $openingHours = explode(";", $row['openingHours']);

  $currentTime = date('H');


  if (in_array($currentTime, $openingHours)) {
      $status = 'Open';
  }
  else {
      $status = 'Closed';
  }

  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo 'status="' . $status . '" ';
  echo 'currentTime="' . $currentTime . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>

我知道代码很长但是这是向您展示的唯一方法,因此您可以告诉我如何解决开放时间的问题并将其与标记和当前时间相关联。

如果您有任何疑问,请不要犹豫,问我 提前致谢

0 个答案:

没有答案