How to limit a conditioned result query in PHP/MYS

2019-07-21 17:00发布

问题:

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!

回答1:

$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)



标签: php mysql limit