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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.