PHP MySQL select random rows

前端 未结 6 1491
深忆病人
深忆病人 2021-02-15 16:47

I have a problem selecting 6 random friends

This is the query I\'ve got so far:

$result = num_rows(\"SELECT * FROM friends WHERE member_id = \'\".$_S         


        
6条回答
  •  抹茶落季
    2021-02-15 17:23

    If you use:

      SELECT * 
        FROM friends 
       WHERE member_id = '".$_SESSION['userid']."' 
    ORDER BY rand() 
       LIMIT 6
    

    If the person only has 3 friends, the query will only show those three - it doesn't mean that the query will always return six rows.

提交回复
热议问题