fetch all rows from mysql db with php using aFetch($sql) problem
i inherited this code from some-one and this only returns the first row it finds:
function getMessages($userID, $from, $limit)
{
$id = 开发者_如何学C$_SESSION['user_id'];
$sql = "SELECT * FROM rc_message_box_table WHERE profile_id_to = {$userID} AND rc_message_box_table.profile_id_from NOT IN (SELECT profile_id_block FROM rc_blocklist_table WHERE profile_id = {$id}) LIMIT {$from}, {$limit}";
$row = $this->aFetch($sql);
return $row;
}
function aFetch($sSql)
{
//print_r($sSql);
$aResults = array();
if(is_string($sSql))
{
$fnSql = $this->query($sSql);
}
while($row = mysql_fetch_assoc($fnSql))
{
$aResults[] = $row;
}
return $aResults;
}
how can i with this code return all rows where profile_id_to = {$userID} ?? thanks
function aFetch($result = false) {
if($result)
return mysql_fetch_assoc($result);
else
return mysql_fetch_assoc($this->result);
}
you can use this function.
Try removing the LIMIT
clause:
SELECT *
FROM rc_message_box_table
WHERE profile_id_to = {$userID}
AND rc_message_box_table.profile_id_from NOT IN
(
SELECT profile_id_block
FROM rc_blocklist_table
WHERE profile_id = {$id}
)
Your result may be limited by $from
, $limit
parameters.
Look at the code where getMessages
is being invoked, and analyse what values it is passing.
精彩评论