blink359 Posted July 2, 2011 Share Posted July 2, 2011 Hi there, having a few problems with my pagination script firstly i get an error "mysql_fetch_array(): supplied argument is not a valid MySQL result resource " before it was doing that all the time (it was doing it on/off for a bit) my search feature didnt seem to be narrowing down the results, Here is my code: <?php //mysql connect is here $name = $_POST['name']; $county = $_POST['county']; $town = $_POST['town']; $max = 10; //amount of articles per page. change to what to want $p ="1"; $p = $_GET['p']; $pp = $p -1; $np = $p +1; $limits = ($p - 1) * $max; //view the news article! if(!$name || !$county || !$town){ $sql = mysql_query("SELECT * FROM pusers LIMIT ".$limits.",$max"); $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM pusers"),0); $totalpages = ceil($totalres / $max); $nplimit = $totalpages; $nplimit++; while($info = mysql_fetch_array($sql)){ echo $info['pname']; echo '<br>'; echo $info['ptown']; } echo'<br>'; if($pp =="0"){ echo(''); }else{ echo'<a href="publist.php?p='. $pp .'">'. Previous .'</a> '; } for($i = 1; $i <= $totalpages; $i++){ echo'<a href="publist.php?p='. $i .'">'. $i .'</a> '; } if($np == $nplimit){ echo(''); }else{ echo'<a href="publist.php?p='. $np .'">'. Next .'</a> '; } }else{ $sql =""; if($name !=""){ $searchsplit = explode(" ", $pubname); $searchsplit0 = $searchsplit['0']; $searchsplit1 = $searchsplit['1']; $searchsplit2 = $searchsplit['2']; $searchsplit3 = $searchsplit['3']; $searchsplit4 = $searchsplit['4']; $searchsplit5 = $searchsplit['5']; $searchsplit6 = $searchsplit['6']; $searchsplit7 = $searchsplit['7']; $searchsplit8 = $searchsplit['7']; $searchsplit9 = $searchsplit['9']; if($searchsplit0 =="the" || $searchsplit0 =="The" || $searchsplit0 =="of" || $searchsplit0 =="Of" || $searchsplit0 =="and" || $searchsplit0 =="And" || $searchsplit0 ==""){ $use0 ="no"; } if($searchsplit1 =="the" || $searchsplit1 =="The" || $searchsplit1 =="of" || $searchsplit1 =="Of" || $searchsplit1 =="and" || $searchsplit1 =="And" || $searchsplit1 ==""){ $use1 ="no"; } if($searchsplit2 =="the" || $searchsplit2 =="The" || $searchsplit2 =="of" || $searchsplit2 =="Of" || $searchsplit2 =="and" || $searchsplit2 =="And" || $searchsplit2 ==""){ $use2 ="no"; } if($searchsplit3 =="the" || $searchsplit3 =="The" || $searchsplit3 =="of" || $searchsplit3 =="Of" || $searchsplit3 =="and" || $searchsplit3 =="And" || $searchsplit3 ==""){ $use3 ="no"; } if($searchsplit4 =="the" || $searchsplit4 =="The" || $searchsplit4 =="of" || $searchsplit4 =="Of" || $searchsplit4 =="and" || $searchsplit4 =="And" || $searchsplit4 ==""){ $use4 ="no"; } if($searchsplit5 =="the" || $searchsplit5 =="The" || $searchsplit5 =="of" || $searchsplit5 =="Of" || $searchsplit5 =="and" || $searchsplit5 =="And" || $searchsplit5 ==""){ $use5 ="no"; } if($searchsplit6 =="the" || $searchsplit6 =="The" || $searchsplit6 =="of" || $searchsplit6 =="Of" || $searchsplit6 =="and" || $searchsplit6 =="And" || $searchsplit6 ==""){ $use6 ="no"; } if($searchsplit7 =="the" || $searchsplit7 =="The" || $searchsplit7 =="of" || $searchsplit7 =="Of" || $searchsplit7 =="and" || $searchsplit7 =="And" || $searchsplit7 ==""){ $use7 ="no"; } if($searchspli8 =="the" || $searchspli8 =="The" || $searchspli8 =="of" || $searchspli8 =="Of" || $searchspli8 =="and" || $searchspli8 =="And" || $searchspli8 ==""){ $use8 ="no"; } if($searchsplit9 =="the" || $searchsplit9 =="The" || $searchsplit9 =="of" || $searchsplit9 =="Of" || $searchsplit9 =="and" || $searchsplit9 =="And" || $searchsplit9 ==""){ $use9 ="no"; } if($searchsplit1 =="" & $searchsplit2 =="" & $searchsplit3 =="" & $searchsplit4 =="" & $searchsplit5 =="" & $searchsplit6 =="" & $searchsplit7 =="" & $searchsplit8 =="" & $searchsplit9 ==""){ $use0="no"; } $sql ='SELECT FROM pusers WHERE pname LIKE \''. $pubname .'\''; if($use0 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit0 .'\''; } if($use1 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit1 .'\''; } if($use2 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit2 .'\''; } if($use3 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit3 .'\''; } if($use4 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit4 .'\''; } if($use5 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit5 .'\''; } if($use6 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit6 .'\''; } if($use7 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit7 .'\''; } if($use8 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchspli8 .'\''; } if($use9 !="no"){ $sql =''.$sql .' OR pname LIKE \''. $searchsplit9 .'\''; } } if($county !="" & $sql ==""){ $county = $_POST['county']; $sql ="SELECT FROM pusers WHERE pcounty = '$county'"; }else if( $county !="" & $sql !=""){ $sql =''. $sql .' AND pcounty = \''. $county .'\''; } if($town !=""){ $tsearchsplit = explode(" ", $town); $tsearchsplit0 = $tsearchsplit['0']; $tsearchsplit1 = $tsearchsplit['1']; $tsearchsplit2 = $tsearchsplit['2']; $tsearchsplit3 = $tsearchsplit['3']; $tsearchsplit4 = $tsearchsplit['4']; if($tsearchsplit0 ==""){ $tuse0 ="no"; } if($tsearchsplit1 ==""){ $tuse1 ="no"; } if($tsearchsplit2 ==""){ $tuse2 ="no"; } if($searchsplit3 ==""){ $tuse3 ="no"; } if($tsearchsplit4 ==""){ $tuse4 ="no"; } if($tsearchsplit1 =="" & $tsearchsplit2 =="" & $tsearchsplit3 =="" & $tsearchsplit4 ==""){ $tuse0 ="no"; } $tsearchsplit2 = explode("-", $town); $tsearchsplit02 = $tsearchsplit2['0']; $tsearchsplit12 = $tsearchsplit2['1']; $tsearchsplit22 = $tsearchsplit2['2']; $tsearchsplit32 = $tsearchsplit2['3']; $tsearchsplit42 = $tsearchsplit2['4']; if($tsearchsplit0 ==""){ $tuse0 ="no"; } if($tsearchsplit1 ==""){ $tuse1 ="no"; } if($tsearchsplit2 ==""){ $tuse2 ="no"; } if($searchsplit3 ==""){ $tuse3 ="no"; } if($tsearchsplit4 ==""){ $tuse4 ="no"; } if($tsearchsplit02 ==""){ $tuse02 ="no"; } if($tsearchsplit12 ==""){ $tuse12 ="no"; } if($tsearchsplit22 ==""){ $tuse22 ="no"; } if($searchsplit32 ==""){ $tuse32 ="no"; } if($tsearchsplit42 ==""){ $tuse42 ="no"; } if($tsearchsplit1 =="" & $tsearchsplit2 =="" & $tsearchsplit3 =="" & $tsearchsplit4 ==""){ $tuse0 ="no"; } if($tsearchsplit12 =="" & $tsearchsplit22 =="" & $tsearchsplit32 =="" & $tsearchsplit42 ==""){ $tuse02 ="no"; } if($sql ==""){ $sql ='SELECT FROM pusers WHERE ptown LIKE \''. $town .'\''; if($tuse0 !="no"){ $sql =''.$sql .' OR ptown LIKE '. $tsearchsplit0 .''; } if($tuse1 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit1 .'\''; } if($tuse2 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit2 .'\''; } if($tuse3 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit3 .'\''; } if($tuse4 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit4 .'\''; } if($tuse02 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit02 .'\''; } if($tuse12 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit12 .'\''; } if($tuse22 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit22 .'\''; } if($tuse32 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit32 .'\''; } if($tuse42 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit42 .'\''; } }else{ $sql =''. $sql .' AND ptown LIKE \''. $town .'\''; if($tuse0 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit0 .'\''; } if($tuse1 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit1 .'\''; } if($tuse2 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit2 .'\''; } if($tuse3 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit3 .'\''; } if($tuse4 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit4 .'\''; } if($tuse02 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit02 .'\''; } if($tuse12 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit12 .'\''; } if($tuse22 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit22 .'\''; } if($tuse32 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit32 .'\''; } if($tuse42 !="no"){ $sql =''.$sql .' OR ptown LIKE \''. $tsearchsplit42 .'\''; } } } $sql =''. $sql .' LIMIT ".$limits.",$max"'; $sql ='mysql_query("'. $sql .'")'; $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM pusers"),0); $totalpages = ceil($totalres / $max); $nplimit = $totalpages; $nplimit++; while($info = mysql_fetch_array($sql2)){ echo $info['pname']; echo $info['ptown']; } echo'<br>'; if($pp =="0"){ echo(''); }else{ echo'<a href="publist.php?p='. $pp .'">'. Previous .'</a> '; } for($i = 1; $i <= $totalpages; $i++){ echo'<a href="publist.php?p='. $i .'">'. $i .'</a> '; } if($np == $nplimit){ echo(''); }else{ echo'<a href="publist.php?p='. $np .'">'. Next .'</a> '; } echo'<br>'; echo $sql; } ?> Any help will be much appriciated, Thanks, Blink359 Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 2, 2011 Share Posted July 2, 2011 oh dear.... You know, you can replace almost all of that code for two blocks with something like this: $searchsplit = explode(" ", $pubname); $sql = "select * from `pusers` where `pname` like '". $pubname ."'"; foreach ($searchsplit as $k=>$v){ if(strtolower($v) != 'the' && strtolower($v) != 'and' strtolower($v) != 'of'){ if(isset($pe) && $pe ==1) $ql .= ' and '; $sql .= "`pname` like '".$v."'"; $pe = 1; } } $sql .= " order by `pname` limit ".$limit.",".$max."x"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.