Multiple data grabs in MySQL
Posted: Wed Dec 03, 2008 12:23 pm
Hi all, I'm curious if anybody around here can help me with a small MySQL problem. Actually, I simply don't know how to do something and I'm hoping some kind soul here knows ...
I have a web site game that I'm programming and right now I'm doing multiple MySQL grabs but I'm sure there must be a better way.
As you can see, what I'm trying to do is get the values for $senior,$child,$male from the same database with only slightly different values. To accomplish this, I'm making three separate calls to the database. Is there a way for me to get all three in a single call?
I have a web site game that I'm programming and right now I'm doing multiple MySQL grabs but I'm sure there must be a better way.
Code: Select all
$query_getpopulation = "SELECT COUNT(id) AS total FROM `c` WHERE v = $v AND age > 65;";
...
$senior = $row_getpopulation['total'];
$query_getpopulation = "SELECT COUNT(id) AS total FROM `c` WHERE v = $v AND age < 18;";
...
$child = $row_getpopulation['total'];
$query_getpopulation = "SELECT COUNT(id) AS total FROM `c` WHERE v = $v AND gender = 1;";
...
$male = $row_getpopulation['total'];