Sql query is not fetching results with variables

Rajiv Mehta

I am trying to execute an sql query using inner join ... The code is below... PART 1 works fine.. and it is creating the value for $query_adlist dynamically.. but when i user this variable $query_adlist in PART 2, it does not fetch results.

PART 1.

$query_adlist="";
$ad_list_countx=mysql_query("SELECT COUNT(ads_id) FROM ads WHERE id=$id");
if($ad_list_countx){$ad_list_count=mysql_fetch_row($ad_list_countx);}
if(isset($ad_list_count) && $ad_list_count[0] > 0)
{
    $query_adlist .="&& (";
    $query_ad_listx=mysql_query("SELECT ads_id FROM ads WHERE id=$id");
    if(isset($query_ad_listx))
    {   
        $sign=" || ";
        $count=1;

            while($query_ad_list=mysql_fetch_array($query_ad_listx))
            {   if($ad_list_count[0] == $count){$sign=") &&";}
                $query_adlist .="ad_clicks.ads_id=".$query_ad_list['ads_id'].$sign;
                $count++;
            }
        }

    }

The value of this variable after the while loop is

$query_adlist="&& (ad_clicks.ad_id=44 || ad_clicks.ad_id=43)";

PART 2. When i execute the code in part 2, it does not fetch result.. but if i type ad_clicks.ad_id=44 || ad_clicks.ad_id=43 instead of variable $query_adlist , it fetches result.. i am confuesd. what m i doing wrong.

$daily_clickx1=mysql_query("
SELECT COUNT(ad_clicks.ad_id) FROM ad_clicks 
INNER JOIN members ON ad_clicks.id=members.id 
WHERE members.ref_id1=$id 
&& ad_clicks.date='$date_modified' $query_adlist
");
Rajiv Mehta

Well it was my mistake .. the column name was wrong.. i figured it out later. column name ads_id was actually ad_id

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related