PDO using fetch() for varchar column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
w1n78
Forum Newbie
Posts: 12
Joined: Mon Mar 08, 2010 10:55 pm

PDO using fetch() for varchar column

Post by w1n78 »

i have the following table

blog_id int(11)
title varchar(255)
blog varchar(4000)
status varchar(1)
date_created datetime
date_modified datetime

if have the following query

Code: Select all

 
$stmt = $dbh->prepare("
SELECT *
FROM `blog`
WHERE `status` <> 'D'
ORDER BY `date_created` DESC
");
 
if ($stmt->execute())
{
  if ($stmt->rowCount() > 0)
  {
    while ($row_blog = $stmt->fetch())
    {
      echo '<div>'.$row_blog['title'].'</div>';
      echo '<div>'.$row_blog['blog'].'</div>';
    }
  }
}
 
the title shows up fine but the blog doesn't. i've even changed blog to varchar(255) thinking it might have something to do w/ the length since my title column is displaying but no luck. am i missing something?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PDO using fetch() for varchar column

Post by Weirdan »

put var_dump($row_blog); into the body of your while() loop and check browser's 'view source' output.
w1n78
Forum Newbie
Posts: 12
Joined: Mon Mar 08, 2010 10:55 pm

Re: PDO using fetch() for varchar column

Post by w1n78 »

thanks that helped a lot. turns out it wasn't saving the $_POST['blog']. which led me to tinymce and jquery. i recoded that part and now it's working as expected.
Post Reply