search error
am 22.11.2006 15:18:16 von Asif Qureshi--0-525755879-1164205096=:52054
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
search error and code has been posted
--------------------------
Got error 28 from table handler
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home2/wwwabcde/public_html/multipurposechain/searchfuncs.ph p on line 294
Got error 28 from table handlerDisplaying results 1-10 of 4541 matches (12.77 seconds)
Result page: 1 2 3 4 5 6 7 8 9 10 Next
------------------------------------------------------------ --------------------
/*******************************************
********************************************/
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
}
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++;
}
if(count($res)!=0)
usort($res, "cmp");
echo mysql_error();
$res['maxweight'] = $maxweight;
$res['results'] = $results;
return $res;
/**/
}
?>
---------------------------------
Sponsored Link
Mortgage rates near 39yr lows. $510,000 Mortgage for $1,698/mo - Calculate new house payment
--0-525755879-1164205096=:52054--