Re: Re: usort(): The argument should be an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Remember14a wrote:>>   $i = 0;>   while ($row = mysql_fetch_row($result)) {>    $res[$i]['title'] = $row[2];>    $res[$i]['url'] = $row[1];>    if ($row[3] != null && $show_meta_description == 1)>     $res[$i]['fulltxt'] = $row[3];>    else>    $res[$i]['fulltxt'] = $row[4];>>>    $res[$i]['size'] = $row[5];>    $res[$i]['weight'] = $result_array[$row[0]];>    $i++;>   }>>  usort($res, "cmp");
The var_dump($res) we asked you to insert output "NULL". That meansthat $res was undefined.
$res is only defined within your loop and your loop is only executedif the search comes back with at least one result.
So what you need to do is make sure that $res is an array, even ifthere are no results from your query. You do this by initialising $resto an array before the loop, just like you've done to $i.
All you need to do is add one line, just before the start of the loop that says:
   $res = array();
-robin
(trying hard to remain patient)

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux