我的代码如下
$sql = <<<SQL
SELECT p . * , s . *
FROM am_user p
INNER JOIN am_user_status s
USING ( user_id )
WHERE product_id =4
AND partner_logo = '1'
ORDER BY RAND( )
LIMIT 6
SQL;
$array = Array();
while ($row = mysql_fetch_array($result)) {
$array[] = $result;
}
echo $array;
但是我收到错误,我只是想把结果放到一个数组中。有谁知道我怎么能做到这一点?
警告:mysql_fetch_array()要求参数1为资源,在第26行的/var/sites/c/xxxxxxx/public_html/index.php中给出null
谢谢!
答案 0 :(得分:4)
$sql = mysql_query("
SELECT p . * , s . *
FROM am_user p
INNER JOIN am_user_status s
USING ( user_id )
WHERE product_id =4
AND partner_logo = '1'
ORDER BY RAND( )
LIMIT 6";
$array = Array();
while ($row = mysql_fetch_array( $sql )) {
$array[] = $row;
}
echo "<pre>";
print_r( $array );
答案 1 :(得分:0)
你有sql语句,忘了把它发送到mysql。
...
$result = mysql_query($SQL); // you forgot this
$array = Array();
while ($row = mysql_fetch_array($result)) {
$array[] = $result;
}
var_dump($array) ; // not echo $array