Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中过滤数组_Php_Sql_Arrays - Fatal编程技术网

在PHP中过滤数组

在PHP中过滤数组,php,sql,arrays,Php,Sql,Arrays,我有一个脚本,它从数据库中获取数据并将其显示在页面上 它按id编号对行进行排序,并按顺序显示 这是剧本 // get the info from the db $sql = "SELECT showtime, html FROM showfeed ORDER BY showtime ASC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

我有一个脚本,它从数据库中获取数据并将其显示在页面上

它按id编号对行进行排序,并按顺序显示

这是剧本

// get the info from the db 
$sql = "SELECT showtime, html FROM showfeed ORDER BY showtime ASC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result))
{ 
   // echo data
   echo $list['html'] . "<hr />";
} // end while
//从数据库获取信息
$sql=“按showtime ASC LIMIT$offset,$rowsperpage从showfeed订单中选择showtime、html”;
$result=mysql\u query($sql,$conn)或trigger\u error(“sql”,E\u USER\u error);
//当有行要提取时。。。
而($list=mysql\u fetch\u assoc($result))
{ 
//回波数据
echo$list['html']。“
”; }//结束时

我想做的是过滤数据,这样如果一行的ID号小于给定的数字,它就不会显示。如果大于某个数字,则会正常显示。

在数据库查询中执行此操作

SELECT ... WHERE id > $certainNumber ...
如果出于任何原因,您希望在PHP中执行此操作:

while ($list = mysql_fetch_assoc($result)) {
    if ($list['id'] < $certainNumber) {
        continue;
    }
    ...
}
while($list=mysql\u fetch\u assoc($result)){
如果($list['id']<$certainNumber){
继续;
}
...
}

假设ID是表中的一个字段:

$sql = "SELECT id, showtime, html FROM showfeed ORDER BY showtime ASC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

// while there are rows to be fetched...
$targetID = 120;
while ($list = mysql_fetch_assoc($result))
{ 
   // echo data
   if ($list['id'] < $targetID) continue;
   echo $list['html'] . "<hr />";
} // end while
过滤sql查询(单词“array”不在这里)

您必须使用sql而不是应用程序过滤查询 诸如此类

SELECT showtime, html FROM showfeed WHERE ID > ?? AND ID < ?? ORDER BY showtime ASC 
从showfeed中选择showtime,html,其中ID>??身份证呢??按showtime ASC订购

你在说什么样的身份证?如果您希望数据库中的每次插入都有一个id,请使用自动递增的主键。您能清楚地说明您想要什么吗?少于某个数字?并且大于某个数字?相同的号码?他们的数据库已经有ID了,这不是问题。这很有效,我使用了第二个脚本。也谢谢大家!
SELECT showtime, html FROM showfeed WHERE ID > ?? AND ID < ?? ORDER BY showtime ASC