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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Parse error: syntax error, unexpected T_STRING on line 72

 

Which is the "Query Failed" line

 

$selectquery = "SELECT * FROM listings WHERE rtype = '$rtype'" . $bed_add . $sleeps_add .";
$result = mysql_query($selectquery);
or die ("Query failed");

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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