Click to See Complete Forum and Search --> : Easy one for the experts


Doc Thirst
05-17-2006, 01:37 PM
I'm doing a sql statment like this:

select * from students where active = '$active' order by lname

Now $active can be 1 or 0 or anything depending on other code (think past, present, all).

so my question is...what is the wild card character to get everything from the table.

thus far I tried:

select * from students where active = '*' order by lname

and

select * from students where active = '%' order by lname

Thanks to anyone with a few seconds to look this over. I tried searching, but I'm a bit lost on the terminology.

NogDog
05-17-2006, 02:03 PM
Well, the simplest (and probably quickest) would just be to omit the where clause if you want all the records:

$where = "";
if(!empty($active) and $active != "all")
{
$where = "where active = '$active'";
}
$query = "SELECT * FROM students $where";

But if you want to use a wildcard in your SQL, then '%' is the character, which needs to be used with 'LIKE':

SELECT * FROM table_name WHERE column LIKE '%'

Doc Thirst
05-17-2006, 02:40 PM
Thanks NogDog, the "like" was throwing me. Works like a charm.