Want to pull random info from database and display it randomly on page.

Discussion in 'PHP' started by Doug the Great, Nov 20, 2007.

  1. #1
    Hello everyone, i'm going to try and explain this to the best of my knowledge.

    I run an arcade site and I get a bunch of featured request.

    http://www.GameFrat.com

    As you can see I have 8 featured games in the featured section (top horizontal). But I want to be able to add more than 8 and the php will pull any 8 from the collection of featured games. I already made a table in my DB called "featured" with 3 fields "Name, Game URL, Thumbnail". I wanna be able to add the info here, display it in html format exactly like I have it now at the top.

    Can someone right me a mock up please so all I have to do is add Game Name / GameURL.html / Thumbnail.jpg

    and it will display in a <a href="$game_url"><img src="/images/$thumbnail">$game_name</a> format and it will only display 8 games.

    Thanks!
    Doug
     
    Doug the Great, Nov 20, 2007 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    hi, i am not really sure on what you want done, is it the form that you want done or the script to pull the random data from the db?
     
    serialCoder, Nov 20, 2007 IP
  3. Doug the Great

    Doug the Great Peon

    Messages:
    548
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well I want the data to be pulled and 8 different games being displayed, and upon refresh 8 new games appear. http://www.BootyArcade.com see there top 8 featured games?
     
    Doug the Great, Nov 20, 2007 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    well, you can probably use Mysql's random() function

    ex: SELECT * FROM tableName ORDER BY RAND() LIMIT 8
     
    serialCoder, Nov 20, 2007 IP
  5. Doug the Great

    Doug the Great Peon

    Messages:
    548
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well I have that but i'm very new at this and that's all I got

    <?PHP
    $rs = mysql_query("SELECT Name AS feat_name, URL AS feat_url, Thumbnail AS feat_thumb from featured ORDER BY RAND() LIMIT 1");
    while (list ($feat_name, $feat_url, $feat_thumb) = @mysql_fetch_row($result3));
    {"<A href=''>$feat_name</a>";
    }
    ?>
    PHP:
     
    Doug the Great, Nov 20, 2007 IP
  6. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #6
    please try this...

    
    <?PHP
    $rs = mysql_query("SELECT Name AS feat_name, URL AS feat_url, Thumbnail AS feat_thumb from featured ORDER BY RAND() LIMIT 8");
    while($row = mysql_fetch_assoc($rs)
    {
      echo '<A href="'.$row['feat_url'].'"><img src="'.$row['feat_thumb'].'"></a>";
    }
    
    ?>
    Code (markup):
    it will output the thumbnail with a link, i'm not sure where to put the name though
     
    serialCoder, Nov 20, 2007 IP
  7. Doug the Great

    Doug the Great Peon

    Messages:
    548
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Parse error: parse error, unexpected '{' in /home/content/u/p/l/uploadstand/html/test.php on line 8
     
    Doug the Great, Nov 20, 2007 IP
  8. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #8
    oh, darn its hard to write code in the editor :rolleyes:

    after </a> just change the double quote " into a single quote '
     
    serialCoder, Nov 20, 2007 IP
  9. Doug the Great

    Doug the Great Peon

    Messages:
    548
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks for the help serialCODER, I got it now.

    <?PHP
    $q=mysql_query("SELECT Name AS feat_name, URL AS feat_url, Thumbnail AS feat_thumb FROM `featured` ORDER BY RAND() ASC LIMIT 8");
    while ($line=mysql_fetch_assoc($q)) {
        echo "<td>";
        echo "<a href=\"$line[feat_url]\"><img src=\"$line[feat_thumb]\" />$line[feat_name]</a>";
        echo "</td>";
    }
    
    
    ?>
    PHP:
     
    Doug the Great, Nov 20, 2007 IP
  10. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #10
    always glad to be of any help :)

    if you have projects that would require extensive coding, i am available :D
     
    serialCoder, Nov 20, 2007 IP