jamesreno20 Posted November 25, 2014 Share Posted November 25, 2014 hi im trying to use query to select from a table where the price is between to values that the user has to input such as min of 3 and max of 8 and return all the fields from the database where it is true im unsure how to do this but this is what i have so far $res = pg_query ($conn, "SELECT ref,artist,composer,genre,title,album,label,price,description FROM music WHERE price = < && > "); echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>"; Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 25, 2014 Share Posted November 25, 2014 Add each less than or greater than condition separately. Example SELECT ref,artist,composer,genre,title,album,label,price,description FROM music WHERE price >= 3 AND price <= 8 Or use a BETWEEN clause SELECT ref,artist,composer,genre,title,album,label,price,description FROM music WHERE price BETWEEN 3 AND 8 Quote Link to comment Share on other sites More sharing options...
jamesreno20 Posted November 25, 2014 Author Share Posted November 25, 2014 Add each less than or greater than condition separately. Example SELECT ref,artist,composer,genre,title,album,label,price,description FROM music WHERE price >= 3 AND price <= 8 Or use a BETWEEN clause SELECT ref,artist,composer,genre,title,album,label,price,description FROM music WHERE price BETWEEN 3 AND 8 i need the numbers to be input from the user do you know how to do this Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 25, 2014 Share Posted November 25, 2014 First check to make sure the min and max inputs are numbers then place the variables inplace of 3 and 8 in your query. Preferably using a prepared query Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.