SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select array question

    Hi, when i select out of a dtabase like i have here:

    PHP Code:
    $advert = @mysql_query("SELECT id, link FROM banner_adverts"); 
     if (!
    $advert) { 
       exit(
    '<p>Error performing query: ' 
           
    mysql_error() . '</p>'); 
     }
    while (
    $row2 mysql_fetch_array($advert)) {  
       
    $adid $row2['id']; 
       
    $adlink $row2['link']; 

    $files = array($adlink);
    $link $files[array_rand($files)];
    }
    echo 
    '<p>' $link .
    '</p>'
    It asigns only the last database entry to $link
    How can i make it random?

    is $adlink an array itself or not?

    Thanks in advance

    David

  2. #2
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change $adlink = $row2['link'] to $adlink[] = $row2['link']
    then change:
    PHP Code:
    $files = array($adlink);
    $link $files[array_rand($files)]; 
    to:
    PHP Code:
    $link $adlink[array_rand($adlink)]; 
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All works now, thank you so much.

    David


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
  •