Home     Articles & Projects     Products & Web Services     Forum

Displaying adsense when a criteria is met

Hi,

I run a directory site which has both free and paid for listings. I am trying to get the details page of the site to display adsene only if the listing is a free. I use a field called rank to do this

<?php
if ($row_ful_site['Rank']='9') {
echo
"ADSENSE TO GO HERE ";
}
?>

I can get it to show the text but when i try and use the google adsense code, things go horribly wrong.

Please could you suggest how i can get this code to show if the listing is ranked at 9

Many thanks

Simon

Hi Simon, The first issue is

Hi Simon,

The first issue is probably the comparison - when comparing values in PHP you need to use ==, as = on it's own is the assignment operator, so in the above code, echo "ADSENSE TO GO HERE "; would be executed all the time.

You may be able to resolve it simply by correcting this aspect, for example:

<?php
if ($row_ful_site['Rank']=='9') {
echo
"ADSENSE TO GO HERE ";
}
?>

Otherwise, it could be that your AdSense codes are breaking the PHP syntax. If this looks like the case, what I would suggest is keeping your AdSense code in a separate file, e.g. adsense.html, and then using require() to call it in; for example:

<?php
if ($row_ful_site['Rank']=='9') {
  require(
"adsense.html");
}
?>

Hope this helps!
Cheers,
David.

Thanks David, It was the

Thanks David,

It was the second issue causing the problems.

Works perfectly now see:

http://www.campsitesandcaravanparks.com/details/Chapmanswell+Caravan+Par...

Thanks for all your help

Best regards

Simon

============
www.4theuk.com