How to prevent repeatable output in PHP MySQL? -
i have create 3 rows of data in mysql database have 4 column dtfrom,dtto,timeout,timein
and have 3 sets of row
dtfrom dtto timeout timein 2016-11-11 2016-11-11 0830 1030 2016-11-12 2016-11-12 0830 1030 2016-11-13 2016-11-13 0830 1030
however, output of "time not passed !" display 3 times below
time not passed ! time not passed ! time not passed !
what want error "time not passed!" display once query. because there's problem if have hundred of data rows. errors appear in hundred of time isn't ?
and second issues cannot run error if input 0845 - 1730 or 0845 - 0945 . it run error if input in database 0830 - 1030
can ? code below
<?php $connect = mysqli_connect("localhost", "root", "", "database"); global $connect; if(isset($_post['submit'])) { $user_id = $_post['user_id']; $dtfrom = $_post['dtfrom']; $dtfrom_user = strtotime($dtfrom); $dtto = $_post['dtto']; $dtto_user = strtotime($dtto); $timeout = $_post['timeout']; $timein = $_post['timein']; $sql = "select * table user_id='{$user_id}' , dtfrom >= '{$dtfrom}' , dtto <= '{$dtto}'"; $run = mysqli_query($connect, $sql); if($run && mysqli_num_rows($run) > 0 ) { while($result = mysqli_fetch_assoc($run)) { $sql1 = "select * table user_id='{$user_id}' , timeout >= '{$timeout}' , timein <= '{$timein}'"; $run1 = mysqli_query($connect,$sql1); if($run1 && mysqli_num_rows($run1) > 0) { while($result1 = mysqli_fetch_array($run1)) { echo "time not passed !<br/>"; } mysqli_free_result($run1); } else { echo "date & time passed !"; echo mysqli_error($connect); } } mysqli_free_result($run); } else { echo "date passed !"; echo mysqli_error($connect); } } ?> <form action="tt.php" method="post"> <table> <tr> <td><i class="fa fa-unlock-alt"></i> </td> <td>user id : </td> <td><input type ="text" name="user_id" size="30"></td> </tr> <tr> <td><i class="fa fa-unlock-alt"></i> </td> <td>date : </td> <td><input type ="text" name="dtfrom" size="30"></td> </tr> <tr> <td><i class="fa fa-unlock-alt"></i> </td> <td>date : </td> <td><input type ="text" name="dtto" size="30"></td> </tr> <tr> <td><i class="fa fa-unlock-alt"></i> </td> <td>timeout : </td> <td><input type ="text" name="timeout" size="30"></td> </tr> <tr> <td><i class="fa fa-unlock-alt"></i> </td> <td>timein : </td> <td><input type ="text" name="timein" size="30"></td> </tr> </table> <p><input class="btnsuccess" type ="submit" name="submit" value="submit"> </p> </form>
thanks in advance.
Comments
Post a Comment