Page 1 of 1

mySQL Select

Posted: Fri Feb 27, 2004 12:20 pm
by [Li] Mark
I am wondering if something is possible to do in mysql. I have one row of data in a mysql table and I would like to select all the information that is not equal to zero. I'd imagine there is a way to do this in PHP or mysql, but I am unable to find that.

For example I've got CGoals = 5, CAssists = 3, CPIM = 0, CPlusMinus = 0. I wanna select just CGoals and CAssists. However there will be many different cases where different variables will be different values.

Any help would be appreciated.

Posted: Sat Feb 28, 2004 11:36 am
by Weirdan

Code: Select all

$res=mysql_query("select * from table");
while($q=mysql_fetch_assoc($res)){
  foreach($q as $name=>$data){
    if($data!==0){
      echo "$name=>$data\n";
    }
  }
 echo "--------------\n";
}
That sould do the trick. Adjust the format to suit your needs.

I don't think it's possible in SQL without any dirty hacks.