0
<?php
// post_view.php
require 'connection.php';
$id =$conn->lastInsertId('id');
$stmt = $conn->prepare('SELECT * FROM posts WHERE id = LAST_INSERT_ID(id) LIMIT 1');


$stmt->execute(array('id' => 'LAST_INSERT_ID(id)'));

 while($row = $stmt->fetchAll(PDO::FETCH_ASSOC)) {
    //$row is an array object? that has one array in index 0
    print_r($row);

echo '<h2>'.$row[':title'].'</h2>';
//echo '<em>Posted '.date('F j<\s\up>S</\s\up>, Y', $row['date']).'</em><br/>';
echo nl2br($row[':body']).'<br/>';
echo '<a href="post_edit.php?id='.$id.'">Edit</a> | <a href="post_delete.php?id='.'id'.'">Delete</a> | <a href="index.php">View All</a>';

echo '<hr/>';
}

It all goes well right up untill i have to echo $row [':title'] and $row['body'], by using print_r($row); i've established that the row returned is an array object? with another array(only one, there is currently only one field in the database )but i cannot acess the contents in the array within the array? any ideas.

Edited by pritaeas: Removed fake signature. Use the signature option in your profile settings.

2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by LastMitch
0

It all goes well right up untill i have to echo $row [':title'] and $row['body'], by using print_r($row); i've established that the row returned is an array object? with another array(only one, there is currently only one field in the database )but i cannot acess the contents in the array within the array? any ideas.

I assume you remove the : in your $row[:title]? I rarely see any code that has that in it.

This question has already been answered. 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.