Current location: Hot Scripts Forums » Programming Languages » PHP » Query problem


Query problem

Reply
  #1 (permalink)  
Old 06-28-05, 12:14 PM
fraggle fraggle is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Query problem

this is my query

$query = "select f1,f2 FROM tablename ORDER By f3 DESC, RAND() limit $offset, $limit WHERE f5='$search'";

result
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource

if i remove the WHERE f5='$search' it works fine, but i need to narrow the results by matching f5 with $search

Thanks in advance
__________________
~Fraggle is Frazzled~
Reply With Quote
  #2 (permalink)  
Old 06-28-05, 01:34 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
the answer is easy
because LIMIT should be the last thing in your query.
PHP Code:

$query "select f1,f2 FROM tablename WHERE f5='$search' ORDER By f3 DESC, RAND() LIMIT $offset$limit"
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 06-28-05, 03:05 PM
fraggle fraggle is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Question thanks

that did the trick, but now my pagination does not work, page 2 onwards has no results?? it pulls back the correct number of pages/links that there sould be....but noting appears.
and if i remove the Where condition - it works perfectly, I get pages and pages of results

Help........
__________________
~Fraggle is Frazzled~

Last edited by fraggle; 06-28-05 at 03:08 PM.
Reply With Quote
  #4 (permalink)  
Old 06-29-05, 03:47 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
are you sure that $search and $offset are passed to the next pages?
also, why would you use RAND() in the ORDER BY ?
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 06-29-05, 10:41 AM
fraggle fraggle is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
they are if I leave out the WHERE condition

RAND() is there to give equal chance for results to be displayed(the records are contact details)
__________________
~Fraggle is Frazzled~
Reply With Quote
  #6 (permalink)  
Old 06-30-05, 01:38 AM
fraggle fraggle is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
anyone got any ideas?
__________________
~Fraggle is Frazzled~
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL Distinct Query problem FunkyM PHP 20 02-28-07 08:33 AM
Thought this query was ok! Aggregate function problem. wwroller65 ASP 1 05-10-04 08:49 AM
Problem Dealing with Null Valuers in SQL Query hai_anilreddy Visual Basic 3 02-08-04 08:39 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.