Jump to content

query select from table where price is < or >


jamesreno20

Recommended Posts

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>";

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

 

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

Archived

This topic is now archived and is closed to further replies.

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