/    Sign up×
Community /Pin to ProfileBookmark

WHERE with 2 conditions?

I wonder may I set 2 different conditions to WHERE when I’m taking data from database? For example I’d like to select data [B]where status=1[/B] & [B]membership=admin[/B], is this possible?

I guess it’s not possible so I’m trying select my 2nd condition using “if” but I have problem with WHILE when I need use both if/else.

Result I need:
[IMG]http://img217.imageshack.us/img217/8089/membership.jpg[/IMG]

My script (doesn’t show results from “else”):

[code=php]
<table>

<?php
$sql=”SELECT * FROM $tbl_name WHERE status = 1 ORDER BY name”;
$result=mysql_query($sql);
?>

<tr><th colspan=”4″>ADMINS</th></tr>

<?php
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){

if($rows[‘membership’] == ‘admin’)
{
?>

<tr><td>…</td><td>…</td><td>…</td><td>…</td></tr>

<?php
// close if statement
}
?>

<tr><th colspan=”4″>MEMBERS</th></tr>

<?php
else {
?>

<tr><td>…</td><td>…</td><td>…</td><td>…</td></tr>

<?php
// close else statement
}
// close while loop
}

// close connection
mysql_close();
?>

</table>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@FINIFApr 24.2010 — Yes you can either use an AND or an OR statement... so it would be:

SELECT * FROM $tbl_name WHERE status=1 AND membership='admin'
×

Success!

Help @Helleshtern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...