doa24uk Posted August 17, 2007 Share Posted August 17, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/ Share on other sites More sharing options...
NArc0t1c Posted August 17, 2007 Share Posted August 17, 2007 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' "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326603 Share on other sites More sharing options...
doa24uk Posted August 17, 2007 Author Share Posted August 17, 2007 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 ."; Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326621 Share on other sites More sharing options...
NArc0t1c Posted August 17, 2007 Share Posted August 17, 2007 What error is it giving? Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326635 Share on other sites More sharing options...
doa24uk Posted August 17, 2007 Author Share Posted August 17, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326638 Share on other sites More sharing options...
NArc0t1c Posted August 17, 2007 Share Posted August 17, 2007 $selectquery = "SELECT * FROM listings WHERE rtype = '$rtype'" . $bed_add . $sleeps_add ."; $result = mysql_query($selectquery) or die ("Query failed"); Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326641 Share on other sites More sharing options...
doa24uk Posted August 17, 2007 Author Share Posted August 17, 2007 Sorry, that was my typo. I've corrected the code to the one you provided and its still giving a T_STRING error. Thanks for your patience! DoA Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326643 Share on other sites More sharing options...
NArc0t1c Posted August 17, 2007 Share Posted August 17, 2007 <?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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65403-solved-box-how-to-select-all/#findComment-326684 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.