php - How to select values where another value is an array? -


i'm trying select values post values array, not know wrong query giving me error. i'm trying know courses added table. have 5 inputs in form.

notice: trying property of non-object in c:\apache\htdocs\xxx\addcourse.php on line 262 

here code

  <?php      if(isset($_post['submit'])) {        $code= isset($_post['code']) ? $_post['code'] : '';       $coursecode = isset($_post['coursecode']) ? $_post['coursecode'] : '';       $both=$code[$x] .' '. $coursecode[$x];        $sqlcourses = "select * courses course_code='$both' order course_id desc limit 5 ";       $resultcourses = $mysqli->query($sqlcourses);           if ($resultcourses->num_rows > 0) {               while($row = $resultcourses->fetch_assoc()) {                  ?>                 </p>                 <p>&nbsp;</p>                 <p>&nbsp;  </p>                 <table width="415" border="0">                 <tr>                 <?php                 $courses=$row["course_code"];                 echo $courses;                 ?>                     </div>                 </tr>                   </table>               <?php              }         }     } ?> 

first, build array of course codes want retrieve; i'm leaving off boundary checks simplicity:

$codes = []; foreach ($_post['code'] $k => $code) {     $codes[] = $code . ' ' . $_post['coursecode'][$k]; } 

then, prepare statement use:

$stmt = $mysqli->prepare("select *    courses    course_code = ?   order course_id desc    limit 5"); 

followed main loop:

foreach ($codes $code) {     $stmt->bind_param('s', $code);     assert($stmt->execute());      $res = $stmt->get_result();     while ($row = $res->fetch_assoc()) {       // ...     } } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -