So I have a two tables users (IDN,RoP) and search_info (IDN, Location, Age) (IDN - is a key column ) I need collect and count the rows from database which have a correct type(RoP) and correct information (Location and Age).
so php :
$location = $_POST['location'];
$age = $_POST['age'];
$type=$_SESSION['type'];
so then I make mysql code...it is doesn't select raws but it is count them. I know that query is not used anymore, but I used it for educational purpose.
$search_result= mysql_query("
SELECT COUNT(a.IDN)
FROM users AS a LEFT JOIN info_search AS b
ON a.IDN = b.IDN
Where a.RoP='$s_type' AND b.Location = '$location' AND b.Age = '$age'
");
$search=mysql_fetch_array($search_result);
So as you can see the code is working but here the staff. I sent the location 1, 2 or 3 , otherwise 0. So if location == 0 I would like to grab from database rows regardless location (in other words - ANY location). Similar with age. is it possible realize on MYSQL? How to change variable that MYSQL grab any location? AND the last question in code. I'm trying to select requirement data, but have problem to output them. so how to print this out?
$search_result= mysql_query("
SELECT COUNT(a.IDN), a.IDN, b.location, b.age
FROM users AS a LEFT JOIN info_search AS b
ON a.IDN = b.IDN
Where a.RoP='$s_type' AND b.Location = '$location' AND b.Age = '$age'
");
i=0;
while ($search=mysql_fetch_array($search_result))
{
$ar_result[] = $search; // some how I get only first row not all of them
$i++;
}