Storing time (periods) (Specific hours) (Durations) using HTML/PHP - Days/Hours -
i have been working on page stores opening hours of days of week using html , php database. in order use data entries compare current time.. did best not working. i'm gonna show html, php, sql codes can tell me how can solve it.
html+css code of form:
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 code:
<?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 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 required fields."; die(); // note } echo "<center></center>"; } ?> but form (the time table (schedule)) not working , not storing data properly. using following:
php code of marker comparison
<?php require("config.php"); function parsetoxml($htmlstr) { $xmlstr=str_replace('<','<',$htmlstr); $xmlstr=str_replace('>','>',$xmlstr); $xmlstr=str_replace('"','"',$xmlstr); $xmlstr=str_replace("'",''',$xmlstr); $xmlstr=str_replace("&",'&',$xmlstr); return $xmlstr; } // opens connection mysql server $connection=mysql_connect ('localhost', $username, $password); if (!$connection) { die('not connected : ' . mysql_error()); } // set active mysql database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('can\'t use db : ' . mysql_error()); } // select rows in markers table $query = "select * markers 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 rows, printing xml nodes each while ($row = @mysql_fetch_assoc($result)){ // add 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>'; ?> i know code long way show can tell me how can fix issue of time of opening hour , link marker , current time.
if have question dont hesitate ask me in advance
Comments
Post a Comment