num_rows is 0 when it should be >0 for php mysqli code
        Posted  
        
            by 
                jpporterVA
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jpporterVA
        
        
        
        Published on 2012-04-13T23:23:34Z
        Indexed on 
            2012/04/13
            23:29 UTC
        
        
        Read the original article
        Hit count: 210
        
My num_rows is coming back as 0, and I've tried calling it several ways, but I'm stuck. Here is my code:
    $conn = new mysqli($dbserver, "dbuser", "dbpass", $dbname);
    // get the data 
    $sql = 'SELECT AT.activityName, AT.createdOn
            FROM userActivity UA, users U, activityType AT  
            WHERE U.userId = UA.userId
            and AT.activityType = UA.activityType
            and U.username = ?
            order by AT.createdOn';             
    $stmt = $conn->stmt_init();
    $stmt->prepare($sql);
    $stmt->bind_param('s', $requestedUsername);
    $stmt->bind_result($activityName, $createdOn);
    $stmt->execute();
    // display the data
    $numrows = $stmt->num_rows;
    $result=array("user activity report for:  " . $requestedUsername . " with " . $numrows . " rows:");
    $result[]="Created On --- Activity Name";
    while ($stmt->fetch())
    {
        $msg = " " . $createdOn . " --- " . $activityName . " ";
        $result[] = $msg;
    }
    $stmt->close();
There are multiple rows found, and the fetch loop process them just fine. Any suggestions on what will enable me to get the number of rows returned in the query?
Suggestions are much appreciated. Thanks in advance.
© Stack Overflow or respective owner