Jump to content

Search Results SQL Problem


Antisocial

Recommended Posts

Hi, I'm fairly new to PHP/MySQL and need some help.

 

I'm trying to make a search page with all the functionality of my results page...

 

Various results are passed: page, orderby, limit

Others gathered from post: search, limit (change)

 

I keep getting the same error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/imomedia.net/httpdocs/jobsheet/search.php on line 95

 

So I'm guessing its my SELECT statement... All the $values look like they return what they're supposed to... Please help!

 

// snip //

 

[pre]if(isset($_GET['orderby']))

{

$orderby=$_GET['orderby'];

}else{

$orderby = "jsid";

}

 

if(isset($_POST['category']))

{

$cat=$_POST['category'];

}else{

$cat = "works";

}

 

if(isset($_POST['gosearch']))

{

$search=$_POST['search'];

}else{

echo "Nothing to search for, please try again";

}

 

$pageNum = 1;

 

// Get number of results per page

if(isset($_POST['filter']))

{

$limit=$_POST['flimit'];

  }else{

    if(isset($_GET['limit']))

    {

    $limit=$_GET['limit'];

    }else{$limit = 20;

  }

}

 

 

// if $_GET['page'] defined, use it as page number

if(isset($_GET['page']))

{

    $pageNum = $_GET['page'];

}else{

$pageNum == 1;

}

 

// counting the offset

$offset = ($pageNum - 1) * $limit;

 

$query = "SELECT * FROM jobsheet WHERE $cat LIKE %$search% ORDER BY $orderby LIMIT $offset,$limit";

$result = mysql_query($query);

$num = mysql_num_rows($result);[/pre]

 

// snip //

Link to comment
https://forums.phpfreaks.com/topic/94873-search-results-sql-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.