if "a" or "b" or "c" then &quo

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
atronmania
Forum Newbie
Posts: 5
Joined: Sat Dec 31, 2005 3:37 am

if "a" or "b" or "c" then &quo

Post by atronmania »

Hi everyone, I'm a newbie so don't laugh ;-)

I have a database with the following rows:
['a01_01']
['a01_02']
['a01_03']
['a01_04']
and each of these rows have a value of 1 or 0

Here is the question, how should i write a condition for this:
if "one of the rows are == 1"
it should echo"something"

thanks in advance!
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Do you mean rows (datasets) or columns (table fields)?


Guess you mean columns, you would read your data into an array and then either loop through the array or check array for including data:

looping (guessed you fetched the array into $row):

Code: Select all

foreach ($row AS $key =>  $value) {
if ($value == 1) {
// do something
break; // stop looping
}
}
checking, if '1' is in the array:

Code: Select all

if (in_array("1", $row)) {
// do something
}
djot
-
atronmania
Forum Newbie
Posts: 5
Joined: Sat Dec 31, 2005 3:37 am

Post by atronmania »

in_array worked perfect!!
Thanks alot
Post Reply