PHP SQL Server替代,适用于MYSQL的TOP和LIMIT [英] PHP SQL Server Alternative for TOP and LIMIT of MYSQL
问题描述
我试图弄清楚如何将我在php mysql中创建的代码转换为php sqlsrv.
I'm trying to figure out on how can i translate the codes I've created in php mysql to php sqlsrv.
基本上,我在MySQL中使用LIMIT来限制分页.但是,SQL Server不支持此功能,而我真的已经很难解决三个月的问题了.
Basically, I used LIMIT in MySQL to limit the pagination. However, this is not supported in SQL Server and I'm really having a hard time like 3 months already to figure this out.
下面是我想在SQLSRV上翻译的MySQL代码:
Below is the MySQL Code I wanted to translate on SQLSRV:
$start="";
$per_page = 1;
$start = $_GET['start'];
$max_pages = ($foundnum / $per_page);
if(!$start)
$start=0;
$getquery = mysql_query("SELECT * FROM knowledgebase WHERE $construct LIMIT $start, $per_page");
下面的代码是我目前在SQLSRV中运行的问题:
And below code is what I currently have issues running in SQLSRV:
$start="";
$per_page = 1;
$start = $_GET['start'];
$max_pages = ($foundnum / $per_page);
if(!$start)
$start=0;
$construct1 ="SELECT * FROM ENSEMBLE WHERE $construct";
$run1=sqlsrv_query($con,$construct1, array(), array('scrollable' => 'keyset'));
我可以在代码$ construct1 ="SELECT * FROM ENSEMBLE WHERE $ construct"的行中轻松添加LIMIT;但我没有这样做,因为无论如何都不可能.
I can easily add LIMIT in the line of code $construct1 ="SELECT * FROM ENSEMBLE WHERE $construct"; but I didn't do it as it is not possible anyway.
任何人都可以帮助我解决如何翻译或重写它? TIA.
Anyone can kindly help me out on how I can possible translate or rewrite it? TIA.
推荐答案
查看这些帖子.从MySQL模拟LIMIT有点棘手.
Look at these posts. Simulating LIMIT from MySQL is little bit tricky.
如何在Microsoft SQL Server中实施LIMIT?
从SQL Server 2012起,有补偿和获取.
SELECT * FROM Table ORDER BY FirstName OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY;
它应该等于LIMIT 10、5.
It should be equivalent to LIMIT 10, 5.
这篇关于PHP SQL Server替代,适用于MYSQL的TOP和LIMIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!