Jump to content


Photo

Help me fix this querry - going nuts!


  • Please log in to reply
2 replies to this topic

#1 tom11011

tom11011
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 September 2006 - 06:54 PM

Basically, there are 2 required fields, but if other fields have data in them, it should query them.  Thenks in advance.

$query = "SELECT * FROM table WHERE sl = '$sl' and state = '$state'";

                if (strlen($type) > 0) {
                        $query = $query + " and type = '$type'";
                        }
                if (strlen($city) > 0) {
                        $query = $query + " and city = '$city'";
                        }
                if (strlen($zip) > 0) {
                        $query = $query + " and zip = '$zip'";
                        }
                if (strlen($status) > 0) {
                        $query = $query + " and status = '$status'";
                        }
                if (strlen($pricemin) > 0) {
                        $query = $query + " and price >= '$pricemin'";
                        }
                if (strlen($pricemax) > 0) {
                        $query = $query + " and price <= '$pricemax'";
                        }
                if (strlen($squarefeetmin) > 0) {
                        $query = $query + " and squarefeet >= '$squarefeetmin'";
                        }
                if (strlen($squarefeetmax) > 0) {
                        $query = $query + " and squarefeet <= '$squarefeetmax'";
                        }
                if (strlen($ppsfmin) > 0) {
                        $query = $query + " and ppsfmin >= '$ppsfmin'";
                        }
                if (strlen($ppsfmax) > 0) {
                        $query = $query + " and ppsfmax <= '$ppsfmax'";
                        }
                $query = $query + " ORDER BY price;";


#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 19 September 2006 - 06:57 PM

close:
<?php
$query = "SELECT * FROM table WHERE sl = '$sl' and state = '$state'";
if (!empty($type)) $query .= " AND type = '$type'";
if (!empty($city)) $query .= " AND city = '$city'";
if (!empty($zip)) $query .= " AND zip = '$zip'";
// and so on
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 tom11011

tom11011
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 September 2006 - 07:16 PM

thanks!  worked.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users