How to limit a conditioned result query in PHP/MYS

2019-07-21 16:50发布

I need to limit the first six results from a query with a condition WHERE.

I would like to do something like that:

mysql_query("CREATE VIEW [test] AS SELECT * FROM table WHERE status=1");

$sel = "SELECT * FROM [test] LIMIT 0,6";

$result = mysql_query($sel);

while($r=mysql_fetch_array($result)){ 
    echo "".$r['id']."<br>";
}

How can I do it? Thanks!

标签: php mysql limit
1条回答
太酷不给撩
2楼-- · 2019-07-21 17:18
$query = "SELECT * FROM `table` WHERE this = 'that' ";
$limit = "ORDER BY index LIMIT 6 ";
$result = mysql_query($query.$limit);

You need to limit your ordered conditional selection. (You probably don't have to order this)

查看更多
登录 后发表回答