tags:

views:

756

answers:

2
$result = mysql_query("SELECT blog_title,body FROM blog WHERE post_id='$id' LIMIT 1") or die (mysql_error());

while ($line = mysql_fetch_assoc($result)){
 $tasks[] = $line;
 $group = $tasks['blog_title'];
 $smarty->assign('view', $tasks);
 $smarty->assign('group', $group);
//here the error.i want to assign blog_title to title
 $smarty->assign('title', "Blog - $group");

newbie,need help.i want to assign blog_title to title any idea?

+3  A: 

You don't need $tasks. This variable messes your script up due to the [] you're using. [] = works just like creating an array using array and applying array_push to it.

Here's what you want to achieve:

$result = mysql_query("SELECT blog_title,body FROM blog WHERE post_id='$id' LIMIT 1") or die (mysql_error());

while ($line = mysql_fetch_assoc($result)){
  $group = $line['blog_title'];
  $smarty->assign('view', $line);
  $smarty->assign('group', $group);
  $smarty->assign('title', "Blog - $group");
}

By the way: in the first line ($result =...), ensure that $id is properly escaped (see mysql_real_escape).

middus
thx middus.works like charm
ruru
A: 

You create a 2 dimensional array that's not supposed to be there. Tasks looks like this now:

<?php
tasks = array(
      0 => array(
        'blog_title' => 'something'
        'body' => 'something else'
      )
    )
?>

So you do $group = $tasks['blog_title'] it does nothing because $tasks only has a key 0, not 'blog_title'. $group[0]['blog_title'] would work but just remove the tasks assignment altogether.

douwe