1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

small scrip to grab URL from database

Discussion in 'PHP' started by vic_msn, Jun 15, 2006.

  1. #1
    i have a scrip that store members url in my database?
    i need to grab a random " username " from the database each time the page refreshes ?
    if possible i also need to grab the corresponding members link from the databse
    please help me? its quite urgent please.
    The database structure is very simple.
     
    vic_msn, Jun 15, 2006 IP
  2. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $query = mysql_query("SELECT username, link FROM db ORDER BY RAND() LIMIT 1");
    while ($row = mysql_fetch_array($query)) {
    echo $row['username'] . " - " . $row['link'];
    }
    
    PHP:
     
    discoverclips, Jun 15, 2006 IP
    Weirfire likes this.
  3. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #3
    thanks for the reply
    can you explain the last statement a little bit
     
    vic_msn, Jun 15, 2006 IP
  4. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #4
    if you mean this one
    echo $row['username'] . " - " . $row['link'];
    Code (markup):
    Then that code display the content of the username field inside your table and the link field.

    example output...

    vic_msn - http://www.siteurl.com/link.html
     
    PinoyIto, Jun 16, 2006 IP
    Weirfire likes this.
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    I didn't realise you could order the database by a random amount. Thanks for that discover! :)
     
    Weirfire, Jun 16, 2006 IP
  6. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #6
    according to my need i changed it as follows
    
    <?php
          $querry = mysql_query("SELECT * FROM rotate_usr ORDER BY RAND() ");
       
          $roww = mysql_fetch_array($querry);
        ?>
    
    
    PHP:
    thank its working
     
    vic_msn, Jun 16, 2006 IP
  7. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #7
    lol, any particular reason for using 2 rs and 2 ws? :)
     
    Weirfire, Jun 16, 2006 IP
  8. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #8
    there was already a $query and $row in the file
    so just like that.
    one more thing it (username) changes after two try's if i hit the refresh button
    but i changes to next value immediately when i type the url in the addressbar and hit the GO button
     
    vic_msn, Jun 16, 2006 IP
  9. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #9
    Ahh right lol

    I normally use $row2 and $query2 but $roww and $querry works for me :D
     
    Weirfire, Jun 16, 2006 IP