0

The code I have is the following

$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;

However I am getting an error, I am just trying to get the results into an array. Does anyone know how I can achieve this?

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /var/sites/c/xxxxxxx/public_html/index.php on line 26

Thanks!

Adam91Holt
  • 1,018
  • 1
  • 14
  • 28
  • Apparently the first paramater for mysql_fetch_array is supposed to be [a resource that is returned as a result of a call to mysql_query()](http://php.net/manual/en/function.mysql-fetch-array.php) – Morklympious Aug 22 '14 at 17:32
  • Be sure you take note that [mysql_ functions are deprecated](http://stackoverflow.com/q/12859942/2370483) – Machavity Aug 22 '14 at 18:03

2 Answers2

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 );
Kodr.F
  • 13,932
  • 13
  • 46
  • 91
0

You have the sql statement, byt forgot to send it to mysql.

...
$result = mysql_query($SQL); // you forgot this

$array = Array();

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

var_dump($array) ; // not echo $array
ThoriumBR
  • 930
  • 12
  • 25