php - mysqli parameterised queries that use arrays -


how can use array sql query , loop through results?

here i've got, i'm not sure how should use implode variables in query

<html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <titleard log</title> <link rel="stylesheet" type="text/css" media="all" href="jsdatepick_ltr.min.css" /> <script type="text/javascript" src="jsdatepick.min.1.3.js"></script> <script type="text/javascript">  window.onload = function() { new jsdatepick({ usemode:2, target:"inputfield", dateformat:"%d-%m-%y" }); new          jsdatepick({ usemode:2, target:"inputfield2", dateformat:"%d-%m-%y" }); };  </script> </head> <body>      <form action="#" method="post">   <input type="checkbox" name="driver[]" value="julia">julia   <input type="checkbox" name="driver[]" value="pete">pete   <input type="text" name="date1" size="12" id="inputfield" />   <input type="text" name="date2" size="12" id="inputfield2" />   <input type="submit" value="submit" name="submit"/>   </form>   <?php  if(isset($_post['submit']) && ($_post['submit'] == "submit"))  {  $date1 = $_post['date1']; $date2 = $_post['date2']; $date1 = date("ymd", strtotime($date1)); $date2 = date("ymd", strtotime($date2)); $drivers = "'".implode("','",$_post['driver'])."'"; }  $mysqli = new mysqli('' );  if($mysqli->connect_error) echo { die("$mysqli->connect_errno: $mysqli->connect _error"); }  $query = "select * wizardlog driver in (?) , date between ? , ? ";  $stmt = $mysqli->stmt_init(); if(!$stmt->prepare($query)) { print "failed prepare statement\n"; } else {               $stmt->bind_param("sss", $drivers, $date1, $date2);               $stmt->execute();             $result = $stmt->get_result();             while ($row = $result->fetch_array(mysqli_assoc))         {             foreach($rows $row)          {          $id = $row['id'];         $driver = $row['driver'];         $date = date("d/m/y", strtotime($date));          $time = $row['time'];           $time = substr($time, 0, 5);         $fname = $row['fname'];         $lname = $row['lname'];         $town = $row['town']; 

any grateful!

a parameter can take place of 1 single scalar value only. not lists of values.

to parameterize list, need number of parameters equal number of elements in list.

but mysqli makes difficult use bind_param() variable number of elements. reason bind_param() needs pass arguments reference, can't pass array; need pass array of references. it's royal pita.

it's easier use pdo instead, because can pass array of values pdostatement::execute() method.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -