[英]Limit amount of records retrieved when using Doctrine DQL in Symfony2
[英]displaying x amount of records using limit
我正在使用一個顯示用戶ID的查詢,而我遇到的問題是,它能夠檢索除最后一條記錄以外的所有數據。 例如,我有這些ID(1,2,3,4,5)。 使用我的腳本,它可以從5檢索到2而忽略1。
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_vivalooks, $vivalooks);
$query_rs_resq = "SELECT user_id FROM users_pics ORDER BY profile_id desc LIMIT 0,5; ";
$rs_resq = mysql_query($query_rs_resq, $vivalooks) or die(mysql_error());
$row_rs_resq = mysql_fetch_assoc($rs_resq);
$totalRows_rs_resq = mysql_num_rows($rs_resq);
HTLM和PHP
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<?php
if($totalRows_rs_resq > 0){
while($row_rs_resq = mysql_fetch_assoc($rs_resq)){
$u_pic_id = $row_rs_resq['u_pic_id'];
?>
<tr>
<td><?php echo $row_rs_resq['u_pic_id']; ?></td>
</tr>
<?php } ?>
</table>
使用我的腳本而不顯示5條記錄,僅顯示4條。
看起來事實是您有兩個語句執行相同的操作。
$row_rs_resq = mysql_fetch_assoc($rs_resq);
刪除其中之一,因為它在執行此操作時會移動數組的內部指針。 就是這樣,或者您重置了內部指針。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.