Reputation: 1754
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?
Upvotes: 0
Views: 1917
Reputation: 612
I believe you can just do count(var) to get the total number of items on your array (seen as the first index is the unique ID.
just add this line to the bottom of your script
$num_rows = count($pushComments);
Upvotes: 0
Reputation: 369
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
Upvotes: 1