![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
php/mysql question, counting number of * results if something = something
Let's say I have a mysql table called john with several duplicate 'status' columns and I run the query:
$res2 = mysql_query("SELECT * FROM john WHERE status='1'"); $row2 = mysql_fetch_assoc($res2); How do I declare how many results there are with this IP? For example if the table had 11 entries with the status=1, how do I declare $total_status = 11 (11 will be changed to the code I need to calculate this) Hope this isn't to confusing, if so let me know and I will post a better example. I basically want to declare how many columns there are with the status of 1. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
SELECT COUNT(*) FROM `john` WHERE `status` = 1
It's always a good idea to backtick fields. Also, don't put INT fields in quotes - it will slow your query down by up to 60%. Note, this method of counting rows has fundamental restrictions. If you have 100 items, and use LIMIT - count will only return the number of LIMIT'd rows. If you want to always have a count of ALL rows that matched the query: SELECT SQL_CALC_FOUND_ROWS * FROM `john` WHERE `status` = 1 Pulling the resulting count out will require another query, but your DB abstractor should take care of it |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
thx, ill try that out
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
so what would i call it?
$statusonecount = ???; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Please read the PHP / mysql manual.
PHP Code:
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
thx, i love u
|
![]() |
![]() ![]() ![]() ![]() ![]() |