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.

display 2 random records from query

Discussion in 'Databases' started by mipa jim, Mar 22, 2007.

  1. #1
    I hate to ask but could someone solve this query for me. I can follow things and
    buthcer them but constructing it is out of my league.

    (idea is to pull 2 random quotes and author from database then
    display the author followed by "--"quote. A line break<br> then repeat the second record>

    
    $query = mysql_query("SELECT * FROM dbquotesnew ORDER BY RAND() LIMIT 0,2");
    
    while($row = mysql_fetch_array($query) ) {
    
    $author_namme = $row[authorname];
    $quote_description = $row[quotedescription];
    
    echo "Quote From" $author_name; "--" echo $quote_description;
    
    Code (markup):
    Can anyone help me with this?
     
    mipa jim, Mar 22, 2007 IP
  2. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #2
    Your code looks like ok. Just complete the loop as below:

    $query = mysql_query("SELECT * FROM dbquotesnew ORDER BY RAND() LIMIT 0,2");

    while($row = mysql_fetch_array($query) ) {

    $author_namme = $row[authorname];
    $quote_description = $row[quotedescription];

    echo "Quote From ".$author_name." -- ".$quote_description."<br>";
    }

    Hope it will help you :)
     
    srobona, Mar 28, 2007 IP
  3. mipa jim

    mipa jim Peon

    Messages:
    261
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks .. something not right. I'll keep on trying. For me it's like hunt and peck typing. Sooner or later... but this time it's been along time.
     
    mipa jim, Mar 28, 2007 IP