简体   繁体   中英

How to limit a conditioned result query in PHP/MYSQL?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM