Below is the detailed code
and error this is giving,
Warning: usort(): The argument should be an array in /home2/wwwabcde/public_html/search/searchfuncs.php on line 311
---------------------------------------------------------------
Once I enter for example,law at
-----------------------------------------------------------------
Let me know precisely where to enter, $res = array();
-----------------------------------------------------------------
error_reporting(E_ALL ^ E_NOTICE);
$include_dir = "include"; include "$include_dir/commonfuncs.php"; function cmp($a, $b) { if ($a['weight'] == $b['weight']) return 0; return ($a['weight'] > $b['weight']) ? -1 : 1;
} function addmarks($a) {
$a = eregi_replace("[ ]+", " ", $a); $a = str_replace(" +", "+", $a); $a = str_replace(" ", "+", $a); return $a; } function makeboollist($a) {
global $entities; while ($char = each($entities)) { $a = eregi_replace($char[0], $char[1], $a); } $a = trim($a); $a = eregi_replace(""", "\"", $a); $returnWords = array(); //get all phrases $regs = Array(); while (eregi("([-]?)\"([^\"]+)\"", $a, $regs)) { if ($regs[1] == '') { $returnWords['+s'][] = $regs[2]; $returnWords['hilight'][] = $regs[2]; } else { $returnWords['-s'][] = $regs[2]; } $a = str_replace($regs[0], "", $a); } $a = strtolower(eregi_replace("[ ]+", " ", $a)); // $a = remove_accents($a); $a = trim($a); $words = explode(' ', $a); if ($a=="") { $limit = 0; } else { $limit = count($words); } $k = 0; //get all words (both include and exlude) $includeWords = array(); while ($k < $limit) { if (substr($words[$k], 0, 1) == '+') { $includeWords[] = substr($words[$k], 1); } else if (substr($words[$k], 0, 1) == '-') { $returnWords['-'][] = substr($words[$k], 1); } else { $includeWords[] = $words[$k]; $returnWords['hilight'][] = $words[$k]; } $k++; } //add words from phrases to includes if (isset($returnWords['+s'])) { foreach ($returnWords['+s'] as $phrase) { $phrase = strtolower(eregi_replace("[ ]+", " ", $phrase)); $phrase = trim($phrase); $temparr = explode(' ', $phrase); foreach ($temparr as $w) $includeWords[] = $w; } } foreach ($includeWords as $word) {
if (!($word =='')) { if (ignoreWord($word)) { $returnWords['ignore'][] = $word;
} else { $returnWords['+'][] = $word; } } }
return $returnWords;
} function ignoreword($word) {
global $common; global $min_word_length; global $index_numbers; if ($index_numbers == 1) { $pattern = "[a-z0-9]+"; } else { $pattern = "[a-z]+"; } if (strlen($word) < $min_word_length || (!eregi($pattern, remove_accents($word))) || ($common[$word] == 1)) { return 1; } else { return 0; } } function search($searchstr, $category, $start, $per_page, $type) {
global $length_of_link_desc,$mysql_table_prefix, $show_meta_description; //find all sites that should not be included in the result
if (count($searchstr['+']) == 0) { return null; } $wordarray = $searchstr['-']; $notlist = array(); $not_words = 0; while ($not_words < count($wordarray)) { $searchword = addslashes($wordarray[$not_words]); $query1 = "SELECT link_id from ".$mysql_table_prefix."link_keyword, ".$mysql_table_prefix."keywords where ".$mysql_table_prefix."link_keyword.keyword_id= ".$mysql_table_prefix."keywords.keyword_id and keyword='$searchword'";
echo mysql_error(); $result = mysql_query($query1); while ($row = mysql_fetch_row($result)) {
$notlist[$not_words]['id'][$row[0]] = 1; } $not_words++; } //find all sites containing the search phrase
$wordarray = $searchstr['+s']; $phrase_words = 0; while ($phrase_words < count($wordarray)) { $searchword = addslashes($wordarray[$phrase_words]); $query1 = "SELECT link_id from ".$mysql_table_prefix."links where fulltxt like '% $searchword%'"; echo mysql_error(); $result = mysql_query($query1); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { return null; } while ($row = mysql_fetch_row($result)) { $phraselist[$phrase_words]['id'][$row[0]] = 1; } $phrase_words++; } if ($category> 0) {
$allcats = get_cats($category); $catlist = implode(",", $allcats); $query1 = "select link_id from ".$mysql_table_prefix."links, ".$mysql_table_prefix."sites, ".$mysql_table_prefix."categories, ".$mysql_table_prefix."site_category where ".$mysql_table_prefix."links.site_id = ".$mysql_table_prefix."sites.site_id and ".$mysql_table_prefix."sites.site_id = ".$mysql_table_prefix."site_category.site_id and ".$mysql_table_prefix."site_category.category_id in ($catlist)"; $result = mysql_query($query1); echo mysql_error(); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { return null; } while ($row = mysql_fetch_row($result)) { $category_list[$row[0]] = 1; } } //find all sites that include the search word
$wordarray = $searchstr['+']; $words = 0; $starttime = getmicrotime(); while ($words < count($wordarray)) { $searchword = addslashes($wordarray[$words]); $query1 = "SELECT distinct link_id, weight from ".$mysql_table_prefix."link_keyword, ".$mysql_table_prefix."keywords where ".$mysql_table_prefix."link_keyword.keyword_id= ".$mysql_table_prefix."keywords.keyword_id and keyword='$searchword' order by weight desc"; $result = mysql_query($query1); $num_rows = mysql_num_rows($result); if ($num_rows == 0) { return null; } if ($type == "or") { $indx = 0; } else { $indx = $words; } while ($row = mysql_fetch_row($result)) { $linklist[$indx]['id'][] = $row[0]; $linklist[$indx]['weight'][$row[0]] = $row[1]; } $words++; } if ($type == "or") {
$words = 1; } $result_array = Array(); if ($words == 1 && $not_words == 0 && $category < 1) { //if there is only one search word, we already have the result
$result_array = $linklist[0]['weight']; } else { //otherwise build an intersection of all the results $j= 1; $min = 0; while ($j < $words) { if (count($linklist[$min]['id']) > count($linklist[$j]['id'])) { $min = $j; } $j++; } $j = 0;
$temp_array = $linklist[$min]['id']; $count = 0; while ($j < count($temp_array)) { $k = 0; //and word counter $n = 0; //not word counter $o = 0; //phrase word counter $weight = 1; $break = 0; while ($k < $words && $break== 0) { if ($linklist[$k]['weight'][$temp_array[$j]] > 0) { $weight = $weight + $linklist[$k]['weight'][$temp_array[$j]]; } else { $break = 1; } $k++; } while ($n < $not_words && $break== 0) { if ($notlist[$n]['id'][$temp_array[$j]] > 0) { $break = 1; } $n++; } while ($o < $phrase_words && $break== 0) {
if ($phraselist[$n]['id'][$temp_array[$j]] != 1) { $break = 1; } $o++; } if ($break== 0 && $category > 0 && $category_list[$temp_array[$j]] != 1) { $break = 1; } if ($break == 0) {
$result_array[$temp_array[$j]] = $weight; $count ++; } $j++; } }//word == 1 $end = getmicrotime()- $starttime;
$results = count($result_array);
if ($results == 0) { return null; } arsort ($result_array); $keys = array_keys($result_array); $maxweight = $result_array[$keys[0]]; for ($i = ($start -1)*$per_page; $i <min($results, ($start -1)*$per_page + $per_page) ; $i++) {
$in[] = $keys[$i]; }
if (!is_array($in)) { $res['results'] = $results; return $res; } $inlist = implode(",", $in);
if ($length_of_link_desc == 0) { $fulltxt = "fulltxt"; } else { $fulltxt = "substring(fulltxt, 1, $length_of_link_desc)"; } $query1 = "SELECT distinct link_id, url, title, description, $fulltxt, size FROM ".$mysql_table_prefix."links WHERE link_id in ($inlist)";
$result = mysql_query($query1); echo mysql_error(); $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"); echo mysql_error(); $res['maxweight'] = $maxweight; $res['results'] = $results; return $res; /**/ } ?> |
--- Begin Message ---
- To: php-general@xxxxxxxxxxxxx
- Subject: Fwd: Re: usort(): The argument should be an array
- From: Remember14a@xxxxxxx
- Date: Wed, 1 Mar 2006 19:35:55 EST
- Full-name: Remember14a
let me give you more details to understand problem with the said code.go to this link, please.in search enter,Justice, you get response without an error.Now enter law,you get error, pasted below,
Warning: usort(): The argument should be an array in /home2/wwwabcde/public_html/search/searchfuncs.php on line 300------------------------------------------------------------------below is part of the code and few lines of code above and below the error point, as the code is more tha 300 lies I had to paste tail end of code at the point of error.----------------------------------------------------------------------$row[4];$res[$i]['size'] = $row[5];$res[$i]['weight'] = $result_array[$row[0]];$i++;}usort($res, "cmp");echo mysql_error();$res['maxweight'] = $maxweight;$res['results'] = $results;return $res;/**/}?>--- Begin Message ---
- To: Remember14a@xxxxxxx
- Subject: Re: Re: usort(): The argument should be an array
- From: Chris <dmagick@xxxxxxxxx>
- Date: Thu, 02 Mar 2006 11:30:56 +1100
- Cc: php-general@xxxxxxxxxxxxx
- In-reply-to: <2d5.3c1a657.31378edf@xxxxxxx>
- References: <2d5.3c1a657.31378edf@xxxxxxx>
- User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)
Remember14a@xxxxxxx wrote:You have written, Now do a var_dump($res) and see what *is* in $res or do print_r(). Can you precisely mention where you want me to put this piece of code.Please include your original post so we can all see it so we don't have to search to find what you're talking about - and highlighting doesn't work because most people will get text-only emails............ $row[4]; $res[$i]['size'] = $row[5]; $res[$i]['weight'] = $result_array[$row[0]]; $i++; } var_dump($res); <--------- usort($res, "cmp"); Then send us the output. -- Postgresql & php tutorials http://www.designmagick.com/
--- End Message ---
--- End Message ---
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php