php - get output of an array and use it mysql query -
i have following php script, selects , insert array user_ids want select.
$query = mysql_query(" select `user_id` users (surname '$name%' , name '$surname%') or (surname '$surname%' , name '$name%') "); while($run = mysql_fetch_array($query)){ $user_id = $run['user_id']; $check_friend_query = mysql_query(" select friends_id friends (user_one='$session_user_id' , user_two ='$user_id') or (user_one='$user_id' , user_two='$session_user_id') "); if( mysql_num_rows($check_friend_query) == 1 ){ $array[] = $user_id; } }
by using following script, output of user ids have in array:
foreach($array $key => $value) { echo "$value </br>"; }
in case ouput prints me 5 user ids : 32, 36, 37, 38, 39.
all want use these values in following sql query:
$sql = " select `name`, `surname`, `email`, `user_id` users ((surname '$name%' , name '$surname%') or (surname '$surname%' , name '$name%')) , `user_id`='$value' ";
but if write above query works 1 value, in case 39 , not all. how can make work all?
try putting sql statement inside foreach loop, way perform command each item in array:
foreach($array $key => $value) { echo "$value </br>"; $sql = " select `name`, `surname`, `email`, `user_id` users ((surname '$name%' , name '$surname%') or (surname '$surname%' , name '$name%')) , `user_id`='$value' "; }
i'm not sure if still want output values or not - if don't need them, take echo command out.
Comments
Post a Comment