i have this array
$row4 = mysql_fetch_array($sql_res);
can anyone help me how to get a random value of $row4['response']
?
the $row4
does not have constant values...
but for now $row4
contains
Array ( [0] => 3 [id] => 3 [1] => where is dryad [react] => where is dryad [2] => Dryad is found in the farthest part of the Dark wilderness. [response] => Dryad is found in the farthest part of the Dark wilderness. [3] => [review] => ) 1
As your code is right now, you would only receive back one query row. This row would just contain your field values for that row. If you are indeed just trying to get a random field value from that single row, you would use:
$randomKey = array_rand($row4,1);
If you meant to ask for a random row from your query, you can do this one of two ways:
1) Use array_rand
to grab a random row and place into $randomRow
:
while($row = mysql_fetch_array($sql_res)) $rows[] = $row;
$randomRow = array_rand($rows);
2) In your query you can specify to only grab 1 random row rather than every result:
SELECT col1 FROM tbl ORDER BY RAND() LIMIT 1;