solomon
solomon

Reputation: 357

output via echo for an input value

<input type="text" name="prod_id" value="<?php echo $product['table']['id']; ?>" />

But it doesn't show up anything although the $product variable is sure to have been properly initialized, what might be the problem ?

Here is the print_r produce

Array ( 
    [0] => Array ( 
        [product_table] => Array ( 
            [id] => 5 
            [quantity] => 20 
            [name] => something 
        ) 
    ) 
) 

Upvotes: 0

Views: 368

Answers (4)

Muhammad Raheel
Muhammad Raheel

Reputation: 19882

Use this

<?php
extract($product[0]);
<input type="text" name="prod_id" value="<?php echo $product_table['id']; ?>" />

Upvotes: 0

Suleman Ahmad
Suleman Ahmad

Reputation: 2113

<input type="text" name="prod_id" value="<?php echo $product[0]['product_table']['id']; ?>" />

Please add index [0] to ensure that if the provided array have multiple values then only first one will be picked as well.

Upvotes: 0

Prabhuram
Prabhuram

Reputation: 1268

You have to access the variable as $product[0]['product_table']['id'] and not $product['table']['id']

Upvotes: 5

Narf
Narf

Reputation: 14752

You're trying to output contents of a non-existing key. You have 'product_table', not 'table'.

Edit:

And it also needs to be $product[0]['product_table']['id'].

Upvotes: 2

Related Questions