Jump to content

Placing ADS on a blog


diminal

Recommended Posts

Hi Everybody,

I'm trying to code a php/mysql blog and I would like to be able place an ad every 5 entries but I can never figure it out. The AD has a separate table in the database. Here's the code I have

$row_count = 1;
$query = mysql_query("SELECT * FROM blog ORDER BY id DESC LIMIT 20") or die(mysql_error());

while($row = mysql_fetch_array($query)) {


$j = mysql_num_fields($query);

for($i=0;$i<$j;$i++) {

$k = mysql_field_name($query,$i);

$$k = $row[$k];

}

print("$body $date etc......");

//PLACE AN AD EVERY 5th ENTRY

$ad_query = mysql_query ("SELECT * FROM advertising ORDER by id DESC");

while ($ad_row = mysql_fetch_array($ad_query)) {
$ad_image = $ad_row["ad_image"];
$ad_link = $ad_row["link"];


$ad = "<table width=690 cellpadding=9 cellspacing=0><tr valign=top><td align=center><a href='$ad_link' target='_blank'><img src='images/ads/$ad_image' class=imagebox></a></td></tr></table>";



$insert_ad = ($row_count % 5) ? $ad2 : $ad;

echo "$insert_ad";


$row_count ++;

}
}

This won't work. Every time I add more AD the placement becomes different. Is there an easier way to do this?

Thanks for the help!


Sincerely,
Dim
Link to comment
https://forums.phpfreaks.com/topic/36486-placing-ads-on-a-blog/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.