mysql query语句_使用带有mysql_query的if语句?

该博客介绍如何通过SQL查询从news表中按submission_date列降序获取结果,并使用while循环处理每条记录。针对不同类型的新闻,如release_date和new_video,提供了不同的输出方式。此外,还提到了在输出用户内容时应考虑输入安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

要按日期订购结果,您可以像这样扩展您的查询

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 .= "

".$row['name']." will be released on

";

break;

case 'new_video':

$html .= "

".$row['name']." has a new video

";

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. */

因为您要插入用户定义的内容,请确保输入

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值