user5000
user5000

Reputation: 129

PHP echo not working even though variable is captured

I am trying to work with this script and get it to echo the results for a variable called bio. The code below does work and when I run var_dump($result); I do get the array from the test table that shows the bio variable data for that record. Oddly, I just can't get that variable to echo using the code below. What am I missing here?

<?php
    include "ASEngine/AS.php"; 
    include "templates/header.php";
    $userId = ASSession::get("user_id");
?>

Testing the bio variable return:

<?php

    $result = $db->select("SELECT * FROM test WHERE user_id = :id", array( 'id' => $userId )); 
    echo $result['bio'];
?>    

Upvotes: 0

Views: 60

Answers (2)

Daryl Gill
Daryl Gill

Reputation: 5524

The array you have given in the comments for vardump will look like this:

array(
    array(
        "user_id" => 2,
        "interests"=>"",
        "bio" => "This is my bio"
    )
);

so you are trying to echo a key which is non existent in the first dimension of the array. Try the following:

echo $result[0]['bio'];

Upvotes: 1

meda
meda

Reputation: 45500

You are not accessing the array properly, should be

echo $result[0]['bio'];

because your dump shows an array of array array(1) { [0]=> array(3) {

Upvotes: 2

Related Questions