i'm running query results database. results saved in array. want know how can use results array further results database in single query. or i'll have use multiple queries?
$query2="select officename office parentofficeid='$parent'"; $result2=mysqli_query($connect,$query2); if(mysqli_num_rows($result2) != 0) { $results= array(); while ($row2 = mysqli_fetch_assoc($result2)) { $results[]=$row2['officename']; } }
the $results array saves results. want use officename values individually. there way use single query? or i'll have process each value?
hi if understand question first want fetch officename
, store them in array , want fetch other info based on officename
. can use one
<?php $db = new mysqli('localhost','root','','databasename'); $result = mysqli_query($db,"select officename office parentofficeid='$parent'") or die(mysqli_error($db)); $officename = array(); while($row = mysqli_fetch_assoc($result)){ $officename[] = $row['officename'];//store office name in array } $officename= join("', '", $officename);//the join() function returns string elements of array. alias of implode() function. $sql = "select * office officename in ('$officename')";// query in condition $result1 = mysqli_query($db,$sql) or die(mysqli_error($db)); while($row1 = mysqli_fetch_assoc($result1)){ echo "<pre>";print_r($row1); }
for more info more join()
. please read http://www.w3schools.com/php/func_string_join.asp
for mysqli
in condition
please read http://www.mysqltutorial.org/sql-in.aspx
Comments
Post a Comment