cs1h Posted October 16, 2007 Share Posted October 16, 2007 Hi, I am using the following script to limit a search result but I keep getting two errors, The script is <?php $page = $_REQUEST['page']; $query = $_POST['query']; $targetb = $_POST['menuFilesDMA']; $targetb = str_replace(' ','_', $targetb); mysql_connect("localhost","xxx","xxx"); mysql_select_db("real") or die("Unable to select database"); // check to see if $page is set if (!$page) { $page = 1; } // Change $query to a request super global after the first page. if($page > 1){ $query = $_REQUEST['query']; } //set up some limits $limit = $page * 10; $limit = $limit - 10; //get the count from the database table $targetb = mysql_real_escape_string($targetb); $type = mysql_real_escape_string($_POST['Type']); $keywords = preg_split("/[\s,]+/", trim($_POST['keyword'])); $keys = ""; foreach($keywords as $K) { $keys .= "AND (Abstract LIKE '%$K%' OR town LIKE '%$K%')"; } $sql_num = "SELECT * FROM jobs WHERE (country='$targetb' OR continent='$targetb') AND (type='$type' OR alltype='$type') $keys"; $num = mysql_num_rows($sql_num); // query your database for the final results $sql_results = "SELECT * FROM jobs WHERE (country='$targetb' OR continent='$targetb') AND (type='$type' OR alltype='$type') $keys ORDER BY id DESC LIMIT $limit,10"; if($num < 5){ $through = $num; } else { $through = $limit + 5; } if ($through > $num){ $through = $total; } if($page > 1){ $from = $limit +1; } else { $from = $limit; } if($from == 0){ $from = $from +1; } echo "<p align=\"center\">"; if ($page > 1) { echo "<a href=\"$PHP_SELF?query=$query&page=".($page -1)."\">Previous</a> "; } if (($num > 5) && (($limit + 5) < $num)) { echo "<a href=\"$PHP_SELF?query=$query&page=".($page +1)."\">Next</a>"; } // Build the list from the $sql query above and display results while($row = mysql_fetch_array($sql_results)) { $Country = $row['country']; $Type = $row['type']; $More = $row['id']; $Title = $row['Title']; $Abs = $row['Abstract']; $Auth = $row['town']; echo "<p align=\"left\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td width=\"14\" height=\"28\" background=\"line_left_corner_top.png\"> </td> <td height=\"28\" colspan=\"4\" background=\"line_top.png\"> </td> <td height=\"28\" background=\"line_right_corner_top.png\"> </td> </tr> <tr> <td width=\"14\" rowspan=\"3\" background=\"line_left.png\"> </td> <td width=\"250\" height=\"21\"><span class=\"style42\">$Title</span></td> <td width=\"154\" height=\"21\"> </td> <td width=\"14\"> </td> <td width=\"128\" height=\"128\" rowspan=\"3\"><img src=\"/searchthumbs/$Country$Type.png\" width=\"128\" height=\"128\" /></td> <td width=\"14\" rowspan=\"3\" background=\"line_right.png\"> </td> </tr> <tr> <td height=\"86\" colspan=\"2\"><span class=\"style41\">$Abs</span></td> <td width=\"14\"> </td> </tr> <tr> <td width=\"250\" height=\"19\"><span class=\"style43\">$Auth</span></td> <td width=\"154\" height=\"19\" align=\"left\" valign=\"bottom\"><span class=\"style39\">>></span> <span class=\"style40\"><a href=more2.php?id=$More>Read More</a> </span> <span class=\"style39\">>></span></td> <td width=\"14\"> </td> </tr> <tr> <td width=\"14\" height=\"19\" background=\"line_left_corner.png\"> </td> <td height=\"28\" colspan=\"4\" background=\"line_base.png\"> </td> <td width=\"14\" height=\"19\" background=\"line_right_corner.png\"> </td> </tr> <tr> <td width=\"14\" height=\"19\"> </td> <td height=\"21\" colspan=\"4\"> </td> <td width=\"14\" height=\"19\"> </td> </tr> </table><p align=\"center\">"; } if ($page > 1) { echo "<a href=\"$PHP_SELF?query=$query&page=".($page -1)."\">Previous</a> "; } if (($num > 5) && (($limit + 5) < $num)) { echo "<a href=\"$PHP_SELF?query=$query&page=".($page +1)."\">Next</a>"; } ?> and the errors are, Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\alimit3.php on line 40 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\alimit3.php on line 76 Does anyone know why this may be? All help will be much appriciated. Thanks Colin Link to comment https://forums.phpfreaks.com/topic/73523-solved-help-limiting-search/ Share on other sites More sharing options...
pocobueno1388 Posted October 16, 2007 Share Posted October 16, 2007 You never actually perform a mysql_query(), you just set it up. <?php $sql_num = "SELECT * FROM jobs WHERE (country='$targetb' OR continent='$targetb') AND (type='$type' OR alltype='$type') $keys"; $result = mysql_query($sql_num)or die(mysql_error()); //<---You need this line $num = mysql_num_rows($result); ?> Link to comment https://forums.phpfreaks.com/topic/73523-solved-help-limiting-search/#findComment-370922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.