Accessing MySql with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjackson111
Forum Newbie
Posts: 9
Joined: Sat Jul 04, 2009 6:44 am

Accessing MySql with PHP

Post by cjackson111 »

I have been scratching my head on this one. I have recently moved to a different web server. I have a simple page, pulling data from a table using a where condition. My condition doesn't seem to be working on the new server. I have made no changes to the code (except for the login and password to connect to the database). If I remove the condition it pulls all of the data fine. I am passing the variables ($price1 and $price2) in the url (http://www.......listing.php?price1=0&price2=100000). It worked perfectly on the old server. Any ideas what I may be doing wrong? The select statement is below --

Doesn't work:
$sql = "select * from listing_gah where price > '$price1' and price < '$price2' order by datesold DESC";


Works:
$sql = "select * from listing_gah order by datesold DESC";


PHP Version 5.2.9
MySQL Version 5

Thanks for any help!!
User avatar
Peter Anselmo
Forum Commoner
Posts: 58
Joined: Wed Feb 27, 2008 7:22 pm

Re: Accessing MySql with PHP

Post by Peter Anselmo »

You could try the "between" syntax as well to see if that works:

Code: Select all

$sql = "SELECT * FROM listing_gah WHERE price BETWEEN '$price1' AND '$price2' ORDER BY datesold DESC";
cjackson111
Forum Newbie
Posts: 9
Joined: Sat Jul 04, 2009 6:44 am

Re: Accessing MySql with PHP

Post by cjackson111 »

Thanks to both of you. Worked like a charm. Don't know why I never used BETWEEN before. Very useful.
Post Reply