要按日期排序结果,您可以像这样扩展查询
SELECT * FROM news ORDER BY `submission_date` DESC //or "ASC" for opposite order
通过使用您的列名。处理不同的结果
while ($row = mysql_fetch_assoc($result)) { //for each returned row
switch($row['type']){ //your column name for field
case 'release_date':
echo $row['name']." will be released on";
break;
case 'new_video':
echo $row['name']." has a new video";
break;
//other cases
default: //if there should be a process for "anything else"-cases
//code
break;
}
}
编辑:
此时的“回声”不会让你开心;我猜你想以 html 格式输出结果;那么您必须在循环开始之前定义一个变量并将其填充到循环中。像这样:
$html = ''; //set variable
while ($row = mysql_fetch_assoc($result)) { //for each returned row
switch($row['type']){ //your column name for field
case 'release_date':
$html .= "<p>".$row['name']." will be released on</p>";
break;
case 'new_video':
$html .= "<p>".$row['name']." has a new video</p>";
break;
//other cases
default: //if there should be a process for "anything else"-cases
//code
break;
}
}
echo $html;
/*$html is now filled with some paragraphs.
You should echo it inside a complete html-structure
with doctype and inside the body-tag.
The position of the echo inside you script depends on the rest of your code. */
因为您要插入用户定义的内容,请确保输入是
- 逃脱
- 修剪或开关盒可能无法工作
请注意 eggyal 的评论,我刚刚拿走了你的代码。不要使用 mysql_query。