I am making a random post generator and the code looks like this:
<?php
$idea_generator = array();
$ideas_sql = "SELECT * FROM Ideas";
$query = mysql_query($ideas_sql);
while($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];
$keywords = $row['keywords'];
//Need to add a link function
array_push($idea_generator, $name);
sort($idea_generator);
$number = count($idea_generator);
//randomly selects idea
$winner = $idea_generator[rand(0, $number -1)];
print strtolower($winner);
}
?>
My problem is that this code returns 3 items out of the test database in different orders. This project is designed to take out only 1 item from this database. Should I stick with this php array method or is there an easier way to accomplish this goal.