Jump to content


Photo

Need help with a select statement


  • Please log in to reply
1 reply to this topic

#1 everythingandtwo

everythingandtwo
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 30 July 2003 - 12:59 AM

If I\'m wanting to select records from a database between two numbers, what would be the best way to write the SQL statement for it?

Here\'s what I have currently, but for some reason it doesn\'t work...

SELECT * FROM guestbook_main WHERE entry_num >= " . $min . " and entry_num <= " . $max . " ORDER BY entry_num DESC;

This doesn\'t return anything, but if I take off the \"and entry_num <= $max\" part of it, it will return all of the entries. I tried using BETWEEN but it didn\'t work either.

Can anyone help me out?

Thanks,
Brad[/code]

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 30 July 2003 - 06:08 AM

Try this query

SELECT * FROM guestbook_main WHERE entry_num between  \'$min\' and \'$max\' ORDER BY entry_num DESC

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users