Hi Jason,

> $sql = "select * from table where age>=$age1 and age<=$age2";
> what if i don't know which is value is greater, age1 or age2?  

PHP has a couple of handy functions for this: min() and max()

$min = min($age1, $age2); // get smallest of two values
$max = max($age1, $age2); // get largest of two values
$sql = "select * from table where age >= $min and age <= $max";

You could also use BETWEEN in your query, which I think reads better:
$sql = "select * from table where age between $min and $max";

This isn't connected to your question, but have a look at this when you have
a spare 5 minutes:
http://adopenstatic.com/faq/selectstarisbad.asp

Cheers
Jon

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to