SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    banner rotation possibly using PHP

    i need to rotate different banners...it would be a really simple script in that i just want a different banner to appear when someone visits the site...i would just do something that rotates images but i need to be able to rotate the HTML with the banners...i've tried phpAdsNew and it's way more complicated than i really need...any suggestions? am i even in the right forum?

  2. #2
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i created a php script that grabs ads from a mysql database, randomizes them and displays them.
    You could code something like that.

    -rsdl

  3. #3
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rsdl
    i created a php script that grabs ads from a mysql database, randomizes them and displays them.
    You could code something like that.

    -rsdl
    you wouldn't happen to wanna post that or send it to me would you?!?!

  4. #4
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha..i'll send you a snippet of the code and you can work from there

    Code:
    include 'config.php';
    include 'connect.php';
    
    
    
    $ads = mysql_query("SELECT * FROM $table_ads")
    	or die(mysql_error());
    $total_ads = mysql_num_rows($ads);
    
    $random = rand(1, $total_ads);
    
    $ad = mysql_query("SELECT * FROM $table_ads WHERE adid='$random'")
    	or die(mysql_error());
    $ad_array = mysql_fetch_array($ad);
    
    $code = $ad_array['ad_code'];
    
    echo"<table class='adBanner'>
    <tr>
    <td width='100%'>
    $code
    </td>
    </tr>
    
    <tr>
    <td width='100%'>
    <p class='adCaption'>Hate the ads?<a href='subscription.php'>Subscribe!</a></p>
    </td>
    </tr>
    </table>";
    pretty simple. not too impressive.

    -rsdl

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, not that efficient.

    SELECT * FROM $table_ads

    just to count rows? not good. you'd use a SELECT COUNT(*) FROM $table_ads for that.

    and how your "random" thing works -- what if there's no adid with that number? adid's probably not made to be sequential.

    i'd replace that first bit of code with this

    PHP Code:
    <?php

    // This is to make the later ORDER BY RAND() better
    mysql_query('SELECT RAND(), RAND(), RAND()');

    $ad mysql_query("SELECT * FROM $table_ads ORDER BY RAND() LIMIT 1")
        or die(
    mysql_error());
    $ad_array mysql_fetch_assoc($ad);

    ?>
    although that won't be too efficient either with a lot of rows because it needs to sort all rows first.

    this might actually work better speed-wise

    PHP Code:
    <?php

    $ads 
    mysql_query("SELECT COUNT(*) FROM $table_ads")
        or die(
    mysql_error());
    $total_ads mysql_result($ads0);

    $random rand(0$total_ads 1);

    $ad mysql_query("SELECT * FROM $table_ads ORDER BY adid LIMIT $random, 1")
        or die(
    mysql_error());
    $ad_array mysql_fetch_assoc($ad);

    ?>
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  6. #6
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea i just noticed that actually


    thanks for the tip!


    -rsdl


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •