php - Return random result from three SQL tables -
i have sql database 3 tables inside called...
fruit name fruit color fruit price
i attempting return random result each of these 3 tables give me example....
apple - green - $10
currently doing running following php 3 times (with different table each)
$result = mysqli_query($con,"select * fruitname"); while($row = mysqli_fetch_array($result)) { echo $row['fruitname']; }
this works fine feeling going wrong way. there way 1 command instead of three?
if want random row, can way:
select * (select * fruitname order rand() limit 1) fn cross join (select * fruitcolor order rand() limit 1) fc cross join (select * fruitprice order rand() limit 1) fp
this returns fields in 1 row.
note random row different arbitrary row. random row means each row has equal chance of being selected. arbitrary row indeterminate. first row in select
without order by
arbitrary, not random.
Comments
Post a Comment