我正在使用查詢來顯示用戶ID和我遇到的問題是,它能夠檢索除最後一條記錄以外的所有數據。例如,我有這些id(1,2,3,4,5)。 隨着我的腳本其能夠從5檢索到2忽略1.使用限制顯示x的記錄數量
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次出現。
您的查詢肯定是返回5個結果嗎? –
也許只是一個超級愚蠢的評論,但你確定數據庫中有超過5條記錄嗎? – Chilion
是約600條記錄 – neiza