html - how to search date field using php - mysqli -


i'm having trouble searching date field of mysql database.. have html form..that allows user choose 3 different ways search database.. field 1 student_id, field 2 lastname, field 3 date. when run program , choose student id, proper result back, when same using last name proper result back, when use date..i not return. happen know result should because see in database..and besides same data record student id, , last name. think might have format, can't figure out..

i not know ajax please don't suggest ajax code right now.

here html code. [code]

-- start javascript --> <script type="text/javascript"> /*<![cdata[ */    function check(){     if(document.lastname.last.value == "" || document.lastname.last.value == null)     {         alert("no last name entered");         return false;     } } function checkdate() { var date_regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/ ; if(!(date_regex.test(testdate))) { return false; }  }  function fieldswap(image){  var sb = document.getelementbyid('sb');  if(sb.value == ""){   sb.style.background = "url(images/"+image+") no-repeat";   } }  function buttonswap(image){  var sb = document.getelementbyid('sb');  sb.src = "images/"+image; } function validate(){ var x = document.information.search.value; if (x.length<10 ||  x.length>10){ alert("student id incorrect"); return false; } }  /*]]> */     </script> <!-- end javascript -->     </head>   <body>  <div id="form_wrap"><!-- start form wrap -->      <div id="form_header">      </div>      <div id="form_body">      <p>search certification request (enter 1 of following):</p>      <form action="search.php" method="post" name="information" id="information" onsubmit="return(validate()or return(checkdate())">         <div class="field">               <select name="type">                 <option value="student_id">student id</option>                 <option value="last_name">last name</option>                 <option value="examdate">exam date</option>             </select>             <input name="typevalue" value="" />         <input type="submit" value="search" />      </form>     </div> </div>        </div><!-- end form wrap -->      </body>     </html>  <form action = "" method = "post">             <div class="field">                 <label = "first_name"> first_name</label>                 <input type = "text" name = "first_name" id = "first_name">             </div>             <div class = "field">                 <label = "last_name"> last_name </label>                 <input type ="text" name = "last_name" id = "last_name">             </div>             <div class = "field">                 <label = "bio"> bio </label>                 <textarea name = "bio" id = "bio"></textarea>                </div>             <input type = "submit" value = "insert">          </form> 

[/code]

here php code

[code]

$records = array();  $typevalue = $_request['typevalue'];   //if did not enter search term give them error if ($typevalue == "") { echo "<p>you forgot enter search term!!!"; exit; } // perform bit of filtering //$typevalue = strtoupper($search);     $typevalue = strip_tags($typevalue);     $typevalue = trim ($typevalue);       $value = $_post['typevalue'];          if($_post['type'] == "student_id")     {         //query $value on student_id          if($result = $db->query("select * records student_id '$typevalue'" )){             if($result->num_rows){                 while($row = $result->fetch_object()){                 $records[] = $row;                 }             $result->free();             }         }     }     elseif($_post['type'] == "last_name")     {         //query $value on last_name         if($result = $db->query("select * records last_name '$typevalue'" )){             if($result->num_rows){                 while($row = $result->fetch_object()){                 $records[] = $row;                 }             $result->free();             }         }     }      elseif($_post['type'] == "examdate")     {         //query $value on date         if($result = $db->query("select * records examdate '$typevalue'" )){             if($result->num_rows){                 while($row = $result->fetch_object()){                 $records[] = $row;                 }             $result->free();             }         }     }     //this counts number or results - , if there wasn't gives them     little     message explaining //$anymatches=$result; //if ($anymatches == 0 ) //{ //echo "sorry, can not find entry match query...<br><br>"; //}  //and remind them searched //echo "<b>results for:</b> " .$typevalue; //} ?>     <!doctype html> <html> <style type="text/css"> th{text-align: left;} table, th, td{ border: 1px solid black;} </style>      <head>     <title>search result</title>     </head>     <body>         <h3> results <?php echo $typevalue ?> </h3>         <?php         if(!count($records)) {         echo 'no records';          } else {          ?>         <table  style="width:100%">>             <th>                  <tr>                     <th>student_id</th>                     <th>first name</th>                     <th>last name</th>                     <th>email</th>                     <th>major</th>                     <th>exam name</th>                     <th>taken class</th>                     <th>prepare</th>                     <th>measureup key</th>                     <th>exam date</th>                     <th>request made on</th>                 </tr>                 </thead>                 <tbody>                 <?php                 foreach($records $r){                 ?>                      <tr>                         <td><?php echo $r->student_id; ?></td>                         <td><?php echo $r->first_name; ?></td>                         <td><?php echo $r->last_name; ?></td>                         <td><?php echo $r->email; ?></td>                         <td><?php echo $r->major; ?></td>                         <td><?php echo $r->examname?></td>                         <td><?php echo $r->taken_class; ?></td>                         <td><?php echo $r->prepare; ?></td>                         <td><?php echo $r->measureupkey; ?></td>                         <td><?php echo $r->examdate; ?></td>                         <td><?php echo $r->request_made; ?></td>                     </tr>                     <?php                     }                      ?>                  </tbody>         </table>         <?php         }         ?> </html>   <html> <head></head> <body> <br/> <a href="query.html">return search </a> </body> </html> 

[/code]

i believe using exam dates session or month can use using date_format function

select * records date_format(examdate, '%y %m') = date_format('$typevalue', '%y %m') order examdate 

or may looking specific date

select * records examdate = '$typevalue'  

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -