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.

two random figures

Discussion in 'PHP' started by jonhyhar, Feb 22, 2010.

  1. #1
    hey guys, in a table as such i could not choose two random figures.

    the table being:


    Code:

    INSERT INTO `c` (`id`, `photo`, `photo1oy`, `categories`, `name`) VALUES


    this way, the id will automatically increase,
    i want to be able to choose 2 random figures (id) as $x and $y,
    but everytime a figure is chosen $x will always be a higher figure than $y.

    does anybody know how this could happen?
     
    jonhyhar, Feb 22, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    If I understood you right:

    
    SELECT * FROM (SELECT * FROM c ORDER BY RAND() LIMIT 2) A ORDER BY id DESC;
    
    Code (markup):
    Regards
     
    koko5, Feb 22, 2010 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    If I'm getting you correctly, you need to select a random picture, and also select another random picture whose id is greater than the id of previously selected id. Is that right?
    You can run 2 queries for that...

    $q=mysql_query("select id, photo from `c` order by rand() limit 1");
    $row= mysql_fetch_assoc($q);
    $id= $row[id];
    "select id, photo from `c` where id>'$id' order by rand() limit 1"

    Thanks :)
     
    JEET, Feb 22, 2010 IP
  4. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    thanks jeet :rolleyes:
     
    jonhyhar, Feb 22, 2010 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Works perfectly!
    Regards :)
     
    JEET, Feb 22, 2010 IP