Jump to content

[SOLVED] <SELECT> box how to select all (*)


doa24uk

Recommended Posts

hi guys,

 

Here is my query

 

$selectquery = "SELECT * FROM listings WHERE rtype = '$rtype' AND bed = '$bed' AND sleeps = '$sleeps' ";

 

my OPTION value is passing "*" to $bed therefore the query looks like this

 

$selectquery = "SELECT * FROM listings WHERE rtype = '$rtype' AND bed = * AND sleeps = '$sleeps' ";

 

However, thats not what I want, because that returns no results. I need it so that if * is selected then it selects all from the $beds column / removes the AND bed = '$bed' from the query.

 

How can I do this?

Link to comment
https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/
Share on other sites

Well, I don't know exactly what you mean by select all from bad column, but here goes.

 

<?php
if ($bed == "*"){
$bed_add = ""; }
else {
$bed_add = " AND bed = " . $bed; }
/* the query */
$selectquery = "SELECT * FROM listings WHERE rtype = '$rtype'" . $bed_add ." AND sleeps = '$sleeps' ";
?>

Its a apartment script, so if the searcher isn't bothered how many bedrooms teh apartment has.

 

Here's my script so far (I need to do the same thing with $sleeps) - its erroring though, could you help me out?

 

if ($sleeps == "*"){
$sleeps_add = ""; }
else {
$sleeps_add = " AND sleeps = " . $sleeps; }
if ($bed == "*"){
$bed_add = ""; }
else {
$bed_add = " AND bed = " . $bed; }

$selectquery = "SELECT * FROM listings WHERE rtype = '$rtype'" . $bed_add . $sleeps_add .";

<?php
if ($sleeps == "*"){
$sleeps_add = ""; }
else {
$sleeps_add = " AND sleeps = " . $sleeps; }
if ($bed == "*"){
$bed_add = ""; }
else {
$bed_add = " AND bed = " . $bed; }

$selectquery = "SELECT * FROM listings WHERE rtype = '$rtype'" . $bed_add . $sleeps_add;
?>

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.