Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Populating a certain value from a field in an SQL DB

Posted on 2003-03-09
4
Medium Priority
?
251 Views
Last Modified: 2006-11-17
I have a MYSQL database running with a single table named 'users'.  In that table I have a field called 'account_status' which can have one of 4 values (0, 1, 2, 5).  Anyhow, what I want to do I call a php script to loop through the whole database and return the number of rows (or users) that contain a value of say, 2.  Then I would print it to my page saying 'There are 'THIS MANY' users awaiting activation".  Really simple question, but I would appreciate a quick answer. Thanks!
0
Comment
Question by:triden
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
carchitect earned 200 total points
ID: 8097250
<?
$connection=mysql_pconnect("localhost","root","root");
$db=msql_select_db("database",$connection);
$sql="select * from users where account_status=2";
$res=mysql_query($sql,$connection);
$rowcnt=mysql_num_rows($res);
echo "No. of usres $rowcnt";
?>
regards
0
 

Author Comment

by:triden
ID: 8099096
Hmm, I get an error:

Warning: Supplied argument is not a valid MySQL result resource in /usr/www/cybermart/admin/main.php on line 13


This is what I have written:

$sql = mysql_query("SELECT * FROM users WHERE account_status='1'");
$result = mysql_query($sql);
$num_activation = mysql_num_rows($result);  //LINE 13

I already have the connection started in an include file.
0
 

Author Comment

by:triden
ID: 8099120
Sorry about that last error, i figured it out. thanks!
0
 
LVL 6

Expert Comment

by:carchitect
ID: 8104284
thx triden for accpting my answer
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question