?
Solved

Populating a certain value from a field in an SQL DB

Posted on 2003-03-09
4
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

752 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