我正在尝试制作一个php / sql页面,它吐出了一个随机故事

时间:2014-04-09 16:37:55

标签: php mysql sql random

我有一个包含7列的SQL数据库表:

  • firstname
  • lastname
  • problem
  • jobs
  • numberofkids
  • family
  • hobby

这些专栏中的每一列都为我提供了故事的部分内容。我试图用他们的变量构建一个随机的文本块;基本上我想创造一个每次都不同的故事。我尝试使用ORDER BY RAND函数,但它目前只吐出1个随机行,而不是随机化每个单独的列。

我是php和sql的新手,我确信这是一个简单的解决方案,但我一直在浏览stackoverflow和论坛几个小时没有运气。这是当前的代码块:

$query = "SELECT firstname, lastname, jobs, family, numberofkids, hobby, problem FROM revgentable ORDER BY RAND () LIMIT 1"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
    echo "". $row['firstname']. " ". $row['lastname']. " is calling in because ". $row['problem']. ". They work as a ". $row['jobs']. " during the week and have ". $row['numberofkids']. " " . $row['family']. ". They spend their weekends ". $row['hobby']. " as a hobby.";
    echo "<br />";
}

0 个答案:

没有答案