0
$e = retrieveEntries($db,$id);

i m passing db connection and entry id to function and function returning mein one when i check with print_r
$e is not returning please help me out

here is the function

function retrieveEntries($db,$id=NULL)
{

    if(isset($id))
    {
        $sql ="SELECT title,entry FROM entries WHERE id =? LIMIT =1";
        $stmt=$db->prepare($sql);
        $stmt->execute(array($_GET['id']));
        $e=$stmt->fetch();

        $fulldisp=1;        
    }
    else
    {
        $sql="Select id,title From entries ORDER BY created DESC";

        foreach ($db->query($sql) as $row)
        {
            $e[] =array($row['id'],$row['title']);
        }
        $fulldisp = 0;
        if(!is_array($e))
        {
            $fulldisp =1;
            $e = array('title'=>'No Entrie Yet',

                    'entry'=>'<a href="/admin.php">Post an entry!</a>' 
                    );
        }

    }
    array_push($e, $fulldisp);

    return  $e;
}
3
Contributors
3
Replies
19
Views
4 Years
Discussion Span
Last Post by skliz
0

Well to solve problems like this you are to apply some nice clean debugging approach.

You are passing your connection object and an ID.

before this statement below.

 if(isset($id))
{

I would advice you perform a simple check on the two parameters that you are passing.

First is your connection parameter. check if it is actually active. you can use the isset() method of php to check in an if statement.

Secondly check the content of the $id. Try to echo the content to see what is there.

0

remember if you pass an invalid id or an id that does not exist you would have an empty resultset.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.