Brandon Kiefer
Brandon Kiefer

Reputation: 349

SQL Query invalid/not displaying results

I am working on a property management software projects and I have been stuck at this point for a while now and I'm getting no where.

I can have one section working then another breaks so I'm chasing my tail here.

I'm trying to accomplish a form to search a database for specific entries such as bedrooms/baths, maxrent/minrent, and sorting functions included in the form.

SQL,

$beds = $_POST['beds'];
$baths = $_POST['baths'];
$minrent = $_POST['minrent'];
$maxrent = $_POST['maxrent'];

$result = mysqli_query($con,"SELECT * FROM units WHERE bed LIKE '%$beds%' OR bath LIKE '%$baths%' AND rent>='$minrent' AND rent<='$maxrent'");
while($row = mysqli_fetch_array($result)){}

Any help to the correct formatting of the sql would be fantastic. Thanks

EDIT: This is just a local project, not trying to make it web-safe. Also, the columns I am using are rent, bed, bath with ~150 records.

EDIT: Solved, changed the column type from TEXT to INT.

Upvotes: 0

Views: 74

Answers (1)

Krish R
Krish R

Reputation: 22711

You can try this, Added ( for OR )

"SELECT * FROM units WHERE (bed LIKE '%$beds%' OR bath LIKE '%$baths%') 
 AND (rent between '$minrent' AND '$maxrent' )"

Upvotes: 2

Related Questions