Re: Sql/PHP question

From: Date: Wed, 16 Apr 2003 18:15:25 +0000
Subject: Re: Sql/PHP question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144166@lists.php.net to get a copy of this message
Ok. I changed the if($department == "all") to if($department != "all") and it works, so what I have is this. $department_query = ""; if ($department != "all") {
    $department="department='$department' and";
} Thanks Mike On Wednesday, April 16, 2003, at 01:05 PM, Michael Lewis wrote:
Mike, Try this: $part=""; if ($department=="all") {
    $part="department='$department' and";
} $query="select * from $database_table where $part location = $location"; Michael ----- Original Message ----- From: "Mike Tuller" <php@ce.anoka.k12.mn.us> To: "php mailing list list" <php-general@lists.php.net> Sent: Wednesday, April 16, 2003 1:58 PM Subject: [PHP] Sql/PHP question
I am creating a page that will generate a report. On the first page I have drop down menus that you can select what you want in the report. The table, department, and location. So in the query, I have this: $query = "select * from $database_table where department = $department and location = $location"; Now this works fine if in the department menu I select a department, and in the location menu I select a location, but I also want to be able to show all. For instance I want to create a report on all items for a single department in all locations. Is there such a thing as a wildcard within a where statement? location = * doesn't work of course, but what else could I use. I could have an if/else statement that if department is set to all, then run one query, and if location is set to all run another, etc. But that could get to be a real mess if I decide to all things later on. Anyone have any ideas on how to go about this? Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#144166) next »