0

This is my table services

id      servicename
901     cleaning
902     washing
903     cooking
904     repair

This is another table payment

customerid      package_details
9088                cleaning,washing
9099                washing,cleaning,repair
9010                cooking,repair,washing

I have tried something like this in php to select id for particular service that the customer opted

$id=$_REQUEST['id'];
$q1= array();
$q2=array();
    $stmti=$db->prepare("SELECT package_details FROM `payment` WHERE customerid=?");
      $stmti->bind_param("s",$id);
      $stmti->execute();
$stmti->bind_result($package);

while ($stmti->fetch()) {
  $q1=explode(",",$package);
for ($i=0; $i <sizeof($q1) ; $i++) {

  $query=$db->prepare("SELECT `id` FROM `services` WHERE servicename=?");
  $query->bind_param("s",$q1[$i]);//error here
  $query->execute();
  $query->bind_result($pid);
  while ($query->fetch()) {
    $q2[$i]=$pid;
  }
}

}

I am getting error in the line having comment above the error is Call to a member function bind_param() on boolean Is there any method to achieve so? with php or only with mysql?

  • This would be a lot easier if you normalize your data. Storing multiple values in one column is a sign that you need a related table instead. – David Oct 08 '17 at 11:43
  • Yes David I know that ,but its already been done by some other developer !! and redoing it would cost me another week !! :( ,is there any shortcut? –  Oct 08 '17 at 11:46
  • As for the error itself, `prepare()` appears to have returned `false`. You need to check for errors from MySQL. The connection object should have an error list property on it. – David Oct 08 '17 at 11:49

0 Answers0