Forum Moderators: coopster

Message Too Old, No Replies

Php Mysql Select Where

can i select multiple values from one row to display?

         

theJoekr

8:12 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Goodday,

I have the following code:
if ($stars){
$query = "SELECT * FROM hotels WHERE active=1 AND stars=$stars ORDER BY stars,priority DESC";
if (!$query) {
die ('invalid query');
}
if ($query){
$result = mysql_query ($query)
or die ("there are no entries");
while ($row = mysql_fetch_row ($result)) {

and then offcourse my output.
Now i want to select multiple values of stars. i have 1,2,3,4,5,6. if i want my page to display them all i thought i add the following:
if ($stars == "all") {

$stars = "1,2,3,4,5,6";
}
but i get no entries, how do i get this right in my code so he will display them all, but still displays one type when i send them the other values?

thx

mcibor

8:18 am on Sep 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If stars is a string with numbers of stars then use the different structure of the query:

$query = "SELECT * FROM hotels WHERE active=1 AND stars IN ($stars) ORDER BY stars,priority DESC";

$stars must be numbers separated by a comma

Michal CIbor

theJoekr

8:28 am on Sep 1, 2005 (gmt 0)

10+ Year Member



Works like a charm, thx