0

I wanted to know how I can store an array variable into a select query, and if its okay to have the following inside a while loop. Thanks in advance.

For example:

$roww = array();
while ($roww = $resultt->fetch_assoc()) { 

$uery = $dbconn->prepare("SELECT user_ids FROM t_friendship WHERE friend_ids = $roww['id'] AND status = 'Pending'");
$uery->execute();
$uery->store_result();

$rows = $uery->num_rows;}
0

4 Answers 4

1

Use curly braces around the array variable like this {$roww['id']}

Also you could construct a string of ids like ('1','2','3') inside the while loop and in one SELECT outside the while you can use IN of MySQL to select the results.

Sign up to request clarification or add additional context in comments.

2 Comments

All The Other Answers Worked Out But Your Was The Most Simple Thanks Man
@TonyThinkk No worries!!
0

Another alternatives for curly brackets would be use of double quotes then a concatenate it.

$query = $dbconn->prepare("SELECT user_ids FROM t_friendship WHERE friend_ids = ".$roww['id']." AND status = 'Pending'");

Comments

0

// Now mysql result set is stored in php variable.

$result = mysql_query($querystring, $dbconn)

$array = array();
while($row = mysql_fetch_object($result))
{
    $array[] = $row;
}  

Comments

0

Use within single quotes

    $uery = $dbconn->prepare("SELECT user_ids FROM t_friendship WHERE friend_ids = '".$roww['id']."' AND status = 'Pending'");
    $uery->execute();

first check out id value just echo $roww['id']. If you getting that value means use above the code

Comments