1

Currently, I'm trying to learn OOP PHP, I was trying to prince the results from a class, however, it doesn't seem to be returning anything, I did try to check for errors "I think" however that too is returning nothing, any advice or additional reading material would be appreciated

<?php 
require ("Database.php");
class Status
{
    private 
    $sessionId,
    $db;

    public function socialStatus($sessionId)
    {
        $db = new Database;

        $query = "SELECT s.userId, f.followingId, s.status 
        FROM followers AS f
        JOIN status AS s ON s.userId = f.userId 
        WHERE s.userId = :sessionId AND f.followingId = :sessionId;";   
        $stmt = $db->prepare($query);  
        $stmt->bindValue(':sessionId', $sessionId);  
        $stmt->execute();   

    }
}

output

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 session_start(); 
$status = new Status;
$sessionId = $_SESSION["userId"];
$status->socialStatus($sessionId);

foreach($status as $key => $value) 
{
    print $value_result = $status->$value['userId']($value['status']);
}
2
  • 1
    How $_SESSION["userId"] will return any value since there is not session_start() and nor you stored any value in session Commented Jan 28, 2018 at 7:16
  • I didn't copy and paste it although I do have it Commented Jan 28, 2018 at 7:21

2 Answers 2

1
$results = $status->socialStatus($sessionId); 
foreach($results as $status){
 //show your status...
}

Don't forget to return your results from your socialStatus() function:

return $stmt->execute(); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much
1

Your socialStatus function should return result of the query. And then output:

$res = $status->socialStatus($sessionId);
foreach($res as $key => $value)
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.