mySQL Select

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
[Li] Mark
Forum Newbie
Posts: 1
Joined: Fri Feb 27, 2004 12:20 pm
Location: Saskatoon
Contact:

mySQL Select

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
Post Reply