![](/img/trans.png)
[英]how to store the value in a variable retrieved from mysql table and to use it in another query using php
[英]how to store the value retrieved from query in a php array
我檢索了一個查詢並嘗試將 id 列存儲在一個數組中。 然后我檢查兩個 arrays 使用 array_intersect 函數找到共同點。
<?php
$a=array(10);
$connection = mysql_connect("localhost","root","");
$db=mysql_select_db("data",$connection);
$res=mysql_query("select * from usertable");
$i=0;
while($row=mysql_fetch_array($res))
{
$a[i]=$row["id"];
$i++;
}
echo $a[1];
$fb_usr_id =json_decode( $_POST['fb_user'], true );
$arr=array($fb_usr_id);
$result = array_intersect($arr, $a);
print_r($result);
?>
我將檢索到的值存儲在數組中的方式是否正確...?? 此代碼的 output 為:
大批 ( )
你這樣做的方式非常好。
您的結果只是意味着 2 arrays 之間沒有連接。
我不知道你為什么這樣做$arr=array($fb_usr_id);
你把一個數組放在一個數組里面?
刪除該行應該會給你一個正確的結果。
現在您正在將array(array(...))
與永遠不會相交的array(...)
進行比較
我會這樣做
<?php
$a;
$connection = mysql_connect("localhost","root","");
$db=mysql_select_db("data",$connection);
$res=mysql_query("select id from usertable");
$i=0;
while($row=mysql_fetch_array($res))
{
$a[]=$row["id"];
}
echo $a[1];
$fb_usr_id =json_decode( $_POST['fb_user'], true );
$arr=array($fb_usr_id);
$result = array_intersect($arr, $a);
print_r($result);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.