Google Adsense + MySql Rows

Discussion in 'Web Design and Development' started by Vitaminwater, Aug 18, 2009.

  1. Vitaminwater macrumors newbie

    Aug 18, 2009
    I'm using a php script to display all rows of a mysql database. I'd like to make a google adsense ad show up at the end of each output, or after each row is displayed. So far the ad is only displaying after the first, or first two, rows are displays.

    Is there another way of going about this?


      $query ="SELECT id, text";
       $query.=" FROM table ORDER BY rand() DESC";
       while (list($id,$text) = 
        mysql_fetch_row($result)) {
    echo $text;
    <script type="text/javascript"><!--
    google_ad_client = "**";
    /* 468x60, created 8/17/09 */
    google_ad_slot = "*****";
    google_ad_width = 468;
    google_ad_height = 60;
    <script type="text/javascript"
  2. SrWebDeveloper macrumors 68000


    Dec 7, 2007
    Alexandria, VA, USA
    Try this, untested as I wrote in a hurry, but you get the idea:

    $ADSense = <<<BUFFER
    <script type="text/javascript"><!--
    google_ad_client = "**";
    /* 468x60, created 8/17/09 */
    google_ad_slot = "*****";
    google_ad_width = 468;
    google_ad_height = 60;
    <script type="text/javascript"

    $query="select id, text from table order by rand() desc";
    while (
    $row=mysql_fetch_assoc($result)) {
    /* Format output as you wish */
    print "ID={$row['id']} TEXT={$row['text']} <br /> $ADSense <br />";

    Just an example that gets the database stuff one random row at a time and display the adsense code after each row, formatted as you wish. $row['id'] will contain the ID and $row['text'] will contain the text for each random row.

    Quick comment - your method likely will upset visitors with all those ads displaying (understatement of the year award). Classic case of just because you can do something does not mean you should. But I supplied you some basic code to help you achieve your goal as stated in this topic.


Share This Page