Rajiv Mehta Rajiv Mehta - 1 year ago 80
MySQL Question

Sql query is not fetching results with variables

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.


$ad_list_countx=mysql_query("SELECT COUNT(ads_id) FROM ads WHERE id=$id");
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");
$sign=" || ";

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


The value of this variable after the while loop is

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

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.

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download