php - how to sent the ANY operand mysql -


so have 2 tables users (idn,rop) , search_info (idn, location, age) (idn - key column ) need collect , count rows database have correct type(rop) , correct information (location , age).

so php :

$location = $_post['location']; $age = $_post['age']; $type=$_session['type']; 

so make mysql code...it doesn't select raws count them. know query not used anymore, used educational purpose.

$search_result= mysql_query("             select count(a.idn)             users left join info_search b                  on a.idn = b.idn               a.rop='$s_type' , b.location = '$location' , b.age = '$age'     "); $search=mysql_fetch_array($search_result); 

so can see code working here staff. sent location 1, 2 or 3 , otherwise 0. if location == 0 grab database rows regardless location (in other words - location). similar age. possible realize on mysql? how change variable mysql grab location? , last question in code. i'm trying select requirement data, have problem output them. how print out?

$search_result= mysql_query("             select count(a.idn), a.idn, b.location, b.age             users left join info_search b                  on a.idn = b.idn               a.rop='$s_type' , b.location = '$location' , b.age = '$age'     "); i=0; while ($search=mysql_fetch_array($search_result)) { $ar_result[] = $search; // how first row not of them $i++; }  

first:

<?php $location = (int) $_post['location']; $age = (int) $_post['age']; $type=$_session['type']; $and_where = array(); if( $age ) {   $and_where [] = "b.age = '{$age}'"; } if( $location ) {   $and_where [] = "b.location = '{$location}'"; }  if( ! empty( $and_where )) {   $and_where = ' , ' . implode( ' , ', $and_where); } else {   $and_where = ''; }  $sql =  "select count(a.idn) ".         "from users left join info_search b ".         "on a.idn = b.idn a.rop='{$s_type}'" . $and_where;  ?> 

second:

$search_result= mysql_query("             select count(a.idn) cnt, a.idn, b.location, b.age             users left join info_search b                  on a.idn = b.idn               a.rop='$s_type' , b.location = '$location' , b.age = '$age'     "); i=0; while ($search=mysql_fetch_array($search_result)) {     $ar_result[] = $search ['cnt']; // how first row not of them     $i++; }  

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -