2016-04-21 80 views
0

我正在使用查询来显示用户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次出现。

+0

您的查询肯定是返回5个结果吗? –

+0

也许只是一个超级愚蠢的评论,但你确定数据库中有超过5条记录吗? – Chilion

+0

是约600条记录 – neiza

回答