I’m trying with some OOP and got a problem with making a mysql_num_rows on a query in a function. I got a function looking like this:
function userPush()
{
$sql = ("SELECT *
FROM pushComments
WHERE pushCommentsFromProfileId='$_SESSION[userId]'
");
$result = mysql_query($sql)or die(mysql_error());
$userPush = Array();
while($row = mysql_fetch_assoc($result)):
$userPush[$row['pushCommentsId']]['pushCommentsId'] = $row['pushCommentsId'];
$userPush[$row['pushCommentsId']]['pushCommentsTimestamp'] = $row['pushCommentsTimestamp'];
$userPush[$row['pushCommentsId']]['pushCommentsFromProfile'] = $row['pushCommentsFromProfile'];
$userPush[$row['pushCommentsId']]['pushCommentsFromProfileId'] = $row['pushCommentsFromProfileId'];
$userPush[$row['pushCommentsId']]['pushCommentsContent'] = $row['pushCommentsContent'];
endwhile;
return $userPush;
}
//
And calling the function like this:
$db -> New woko();
$pushComments = $db->pushComments();
How would I create a mysql_num_rows here? Can I call a $count variable from the function, and how?
You can do it like this since the data that is being returned is an array
$db -> New woko();
$pushComments = $db->pushComments();
$pushCommentsCount = count($db->pushComments());
hope that helps