0
$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?

0

2 Answers 2

3

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.