mysql - Something wrong with mysqli_fetch_array in php? -


i trying create booking system in php , mysql datepicker. when user selects date table available period times should displayed. if time frame available, user should use radio input , book period of time. if i'm using "order start asc limit 1". gives me 8:22 exists, , it's correct, not gives me second statement, 8:30 exists. instead, 8.30 creates available time frame 8:30-8:38. if i'm using "order start asc". multiplies information based on how many records have in database. can't see wrong ! bellow code mysql table:

create table if not exists `bookings` (   `id` int(100) not null auto_increment,   `date` date not null,   `start` enum('8:22-8:30','8:30-8:38','8:38-8:46','8:46-8:54','8:54-9:02','9:02-9:10','9:18-9:26','9:26-9:34','9:34-9:42','9:42-9:50','9:50-10:58','10:58-11:06','11:06-11:14','11:14-11:22','11:22-11:30','11:30-11:38','11:38-11:46','11:46-11:54','11:54-12:02','12:30-12:38','12:38-12:46','12:46-12:54','12:54-13:02','13:02-13:10','13:10-13:18','13:18-13:26','13:26-13:34','13:34-13:42','13:42-13:50','13:50-13:58','13:58-14:06','14:06-14:14','14:14-14:22','14:22-14:30','14:30-14:38','14:38-14:46','14:46-14:54','14:54-15:02','15:02-15:10','15:10-15:18','15:18-15:26','15:26-15:34') collate utf8_unicode_ci not null,   `booked` enum('0','1') collate utf8_unicode_ci not null,   `name` varchar(100) collate utf8_unicode_ci not null,   `email` varchar(200) collate utf8_unicode_ci not null,   `phone` varchar(50) collate utf8_unicode_ci not null,   primary key (`id`),   unique key `start` (`start`) ) engine=myisam  default charset=utf8 collate=utf8_unicode_ci auto_increment=5 ;  -- -- dumping data table `bookings` --  insert `bookings` (`id`, `date`, `start`, `booked`, `name`, `email`, `phone`) values (2, '2016-05-06', '8:30-8:38', '1', 'vcv', 'vxcv', 'xcvvc'), (1, '2016-05-06', '8:22-8:30', '1', 'zxccxz', 'xczcc', 'zxczxc'), (4, '2016-05-09', '9:02-9:10', '1', '', '', ''), (3, '2016-05-09', '8:38-8:46', '1', '', '', ''); 

and code index.php is:

    <?php $conn = mysqli_connect("localhost", "", "", "");  $post_at = ""; $post_at_to_date = "";  $querycondition = ""; if(!empty($_post["search"]["post_at"])) {                $post_at = $_post["search"]["post_at"];     list($fid,$fim,$fiy) = explode("-",$post_at);      $post_at_todate = date('y-m-d');     if(!empty($_post["search"]["post_at"])) {         $post_at_to_date = $_post["search"]["post_at"];         list($tid,$tim,$tiy) = explode("-",$_post["search"]["post_at"]);         $post_at_todate = "$tiy-$tim-$tid";     }      $querycondition .= "where date = '" . $post_at_todate . "' "; }  $sql = "select * bookings " . $querycondition . " order start asc limit 1"; $result = mysqli_query($conn,$sql);  ?>  <html> <head> <title>recent articles</title>       <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">  <style> .table-content{border-top:#cccccc 4px solid; width:50%;} .table-content th {padding:5px 20px; background: #f0f0f0;vertical-align:top;}  .table-content td {padding:5px 20px; border-bottom: #f0f0f0 1px solid;vertical-align:top;}  </style> </head>  <body><input type="text" id="field_results" name="field_results" />  ... <div class="demo-content">     <h2 class="title_with_link">recent articles</h2>   <form name="frmsearch" method="post" action="">  <p class="search_input">         <input type="text" placeholder="from date" id="post_at" name="search[post_at]" value="<?php echo $post_at; ?>" class="input-control" />               <input type="submit" name="go" value="search" > </p> <?php if(!empty($result))    { ?> <table class="table-content">       <thead>     <tr>        <th width="30%"><span>day</span></th>       <th width="50%"><span>time period</span></th>                  <th width="20%"><span>book</span></th>           </tr>   </thead> <tbody> <?php      //while ($row=mysqli_fetch_row($result))     while($row = mysqli_fetch_array($result)) {         if(preg_match('/8:22-8:30/',$row['start'])==true){             echo "8:22 exists";         }else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>8:22-8:30</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '8:22-8:30' .'"></td>';             echo "</tr>";         }         if(preg_match('/8:30-8:38/',$row['start'])==true){             echo "8:30 exists";         }else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>8:30-8:38</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '8:30-8:38' .'"></td>';             echo "</tr>";         }         if(preg_match('/8:38-8:46/',$row['start'])){             echo "8:38 exists";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>8:38-8:46</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '8:38-8:46' .'"></td>';             echo "</tr>";         }         if(preg_match('/8:46-8:54/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>8:46-8:54</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '8:46-8:54' .'"></td>';             echo "</tr>";         }         if(preg_match('/8:54-9:02/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>8:54-9:02</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '8:54-9:02' .'"></td>';             echo "</tr>";         }         if(preg_match('/9:02-9:10/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>9:02-9:10</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '9:02-9:10' .'"></td>';             echo "</tr>";         }         if(preg_match('/9:18-9:26/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>9:18-9:26</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '9:18-9:26' .'"></td>';             echo "</tr>";         }         if(preg_match('/9:26-9:34/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>9:26-9:34</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '9:26-9:34' .'"></td>';             echo "</tr>";         }         if(preg_match('/9:34-9:42/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>9:34-9:42</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '9:34-9:42' .'"></td>';             echo "</tr>";         }         if(preg_match('/9:42-9:50/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>9:42-9:50</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '9:42-9:50' .'"></td>';             echo "</tr>";         }         if(preg_match('/9:50-10:58/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>9:50-10:58</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '9:50-10:58' .'"></td>';             echo "</tr>";         }         if(preg_match('/10:58-11:06/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>10:58-11:06</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '10:58-11:06' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:06-11:14/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:06-11:14</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:06-11:14' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:14-11:22/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:14-11:22</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:14-11:22' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:22-11:30/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:22-11:30</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:22-11:30' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:30-11:38/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:30-11:38</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:30-11:38' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:38-11:46/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:38-11:46</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:38-11:46' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:46-11:54/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:46-11:54</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:46-11:54' .'"></td>';             echo "</tr>";         }         if(preg_match('/11:54-12:02/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>11:54-12:02</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '11:54-12:02' .'"></td>';             echo "</tr>";         }         if(preg_match('/12:30-12:38/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>12:30-12:38</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '12:30-12:38' .'"></td>';             echo "</tr>";         }         if(preg_match('/12:38-12:46/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>12:38-12:46</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '12:38-12:46' .'"></td>';             echo "</tr>";         }         if(preg_match('/12:46-12:54/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>12:46-12:54</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '12:46-12:54' .'"></td>';             echo "</tr>";         }         if(preg_match('/12:54-13:02/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>12:54-13:02</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '12:54-13:02' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:02-13:10/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:02-13:10</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:02-13:10' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:10-13:18/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:10-13:18</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:10-13:18' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:18-13:26/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:18-13:26</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:18-13:26' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:26-13:34/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:26-13:34</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:26-13:34' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:34-13:42/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:34-13:42</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:34-13:42' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:42-13:50/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:42-13:50</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:42-13:50' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:50-13:58/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:50-13:58</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:50-13:58' .'"></td>';             echo "</tr>";         }         if(preg_match('/13:58-14:06/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>13:58-14:06</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '13:58-14:06' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:06-14:14/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:06-14:14</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:06-14:14' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:14-14:22/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:14-14:22</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:14-14:22' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:22-14:30/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:22-14:30</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:22-14:30' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:30-14:38/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:30-14:38</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:30-14:38' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:38-14:46/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:38-14:46</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:38-14:46' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:46-14:54/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:46-14:54</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:46-14:54' .'"></td>';             echo "</tr>";         }         if(preg_match('/14:54-15:02/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>14:54-15:02</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:54-15:02' .'"></td>';             echo "</tr>";         }         if(preg_match('/15:02-15:10/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>15:02-15:10</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '14:54-15:02' .'"></td>';             echo "</tr>";         }         if(preg_match('/15:10-15:18/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>15:10-15:18</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '15:10-15:18' .'"></td>';             echo "</tr>";         }         if(preg_match('/15:18-15:26/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>15:18-15:26</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '15:18-15:26' .'"></td>';             echo "</tr>";         }         if(preg_match('/15:26-15:34/',$row['start'])){             echo "";         } else {             echo "<tr>";             echo "<td>$post_at</td>";             echo "<td>15:26-15:34</td>";             echo '<td><input class="text" type="radio" id="rez" name="rez" value="'. '15:26-15:34' .'"></td>';             echo "</tr>";         }  ?>     <tr>       </tr> <?php     } ?> <tbody> </table> <?php } ?> </form> </div> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $.datepicker.setdefaults({ showon: "button", buttonimage: "datepicker.png", buttontext: "date picker", buttonimageonly: true, dateformat: 'dd-mm-yy'   }); $(function() { $("#post_at").datepicker(); $("#post_at_to_date").datepicker(); }); </script> <script> $(document).ready(function () { $(":radio").on('click', function () {      var fields = '';     $(":radio").each(function () {         if (this.checked) {             fields += $(this).val() + ' ';         }     });     $('#field_results').val($.trim(fields))  }); }); </script> </body></html> 

from "bookings" db table remove "unique key start (start)".

if set "unique key" field every time field value must unique.

ex. if unique field value blank 1 record, other records should not blank.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -