$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;
}

try to check if the query is returning any rows

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.