Results 1 to 4 of 4

Thread: PHP / MySQL Keywords

  1. #1
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default PHP / MySQL Keywords

    Hi i would like to show a random ad based on keyword.
    For e.g i have 3 technology ads and i would like the PHP to randomly choose a ad to show this is what i have.

    Code:
    <?php
    $ads = "SELECT * FROM ads ORDER BY RAND()LIMIT 1";
    $adsresult = mysql_query($ads);
    
    while($row = mysql_fetch_array($adsresult)) echo"{$row['file']}&displaywidth={$row['displaywidth']}&displayheight={$row['displayheight']}";?>
    This script does work but it just randomly chooses the ad to show.
    Thanks
    The web in one word.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The only thing I could think of is either adding a new column to your db that holds a list of keywords, then you could call the ads like so:

    Code:
    $ads = "SELECT * FROM `ads` WHERE `keywords` LIKE '%".$_GET['keyword']."%' ORDER BY RAND() LIMIT 1";
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I got it to work however it there away to make it = not like i tryed replacing the LIKE with = and it did not work
    Last edited by queerfm; 03-21-2008 at 07:13 AM.
    The web in one word.

  4. #4
    Join Date
    May 2006
    Posts
    266
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ok got it working, Now another problem sorry

    I have 20 items in jokes
    i would like to show 6 items per page

    so like
    ID= 1><10
    then at bottom of page it say
    next

    it reloads the same page but
    ID=11><20

    I hope that helps
    The web in one word.

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
  •