diminal Posted January 31, 2007 Share Posted January 31, 2007 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 More sharing options...
boo_lolly Posted January 31, 2007 Share Posted January 31, 2007 your problem is here[code]$insert_ad = ($row_count % 5) ? $ad2 : $ad;echo "$insert_ad";[/code]it should look like this:[code](($row_count % 5 == 0) ? (echo $ad2) : (echo $ad));[code]there's no need for $insert_ad.[/code][/code] Link to comment https://forums.phpfreaks.com/topic/36486-placing-ads-on-a-blog/#findComment-173710 Share on other sites More sharing options...
diminal Posted February 1, 2007 Author Share Posted February 1, 2007 Hi, I got a "Parse error: syntax error, unexpected T_ECHO..." when I tried that code. What could be wrong? Link to comment https://forums.phpfreaks.com/topic/36486-placing-ads-on-a-blog/#findComment-174492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.