Pętla foreach generuje dziwną treść

0

Witam, mam dosyć dziwny problem ze Smarty. Mianowicie w bazie jest zapisany tylko jeden testowy post, a Smarty dodaje do tego cztery inne z dziwnymi cyframi:
dziwne posty.JPG

Kod szablonu:

{config_load file="main.conf" section="conf_index"}
{include file="header.tpl"}

            <h1>Forum</h1>
            {nocache}
            {if isset($smarty.session.login)}
            
                {foreach from=$data item=posty}
                        <table class="post">
                <thead>
                    <tr>
                        <td class="postuser">{$posty.name}</td>
                        <td>{$posty.date}</td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            {if $posty.avatar != ''}
                            <img class="userimage" src="{$posty.avatar}" alt="Obrazek użytkownika" />
                            {/if}
                            <ul class="about">
                                <li>Ostatnio wizyta: {$posty.lastenter}</li>
                                <li>Postów: {$posty.postcount}</li>
                            </ul>
                        </td>
                        <td class="postcontent">
                        {$posty.content}
                        <hr />
                        <div class="postdescription">{$posty.description}</div>
                        </td>
                    </tr>
                </tbody>
            </table>
            {/foreach}
                
            {else}
                <div style="width: 100%; text-align: center;">
                    <h2>To forum jest przeznaczone wyłącznie dla osób zarejestrowanych</h2>
                    <img src="images/lock.png" alt="Zablokowane przez administratora" /></div>
            {/if}
            {/nocache}
{include file="footer.tpl"}

index.php:

if ($_GET['page']=='' || !is_numeric($_GET['page'])) {
	$page = PagesCount($config['postsperpage']);
    }
    else{
	$page['page'] = $_GET['page'];
    }
    
    if (IsUserLogged())
    {
        $data = GetPosts(($page * 10) - 10, $config['postsperpage'], true);
        
        $smarty->assign('data', $data);
    }
    $smarty->display("index.tpl");

fragment functions.php:

function GetPosts($start, $count, $userinfo)
{
	$q = "SELECT `id`, `user`, `date`, `content`, `description`, `lastmodify` FROM `posts` ORDER BY  `date` ASC LIMIT " . $start . ", " . $count;
	$r = mysql_query($q);
	// List posts
	$i = 0;
	while ($c = mysql_fetch_row($r)){
		$i = $i + 1;
		$posts[$i]['id'] = $c[0];
		$posts[$i]['user'] = $c[1];
		$posts[$i]['date'] = $c[2];
		$posts[$i]['content'] = $c[3];
		$posts[$i]['description'] = $c[4];
		$posts[$i]['lastmodify'] = $c[5];
                if ($userinfo)
                {
                    $uinfo = GetUserInfo($c[1]);
                    $posts[$i]['name'] = $uinfo['name'];
                    $posts[$i]['postcount'] = UserPostCount($c[1]);
                    $posts[$i]['avatar'] = $uinfo['avatar'];
                    $posts[$i]['lastenter'] = $uinfo['lastenter'];
                    $posts['weightbegin'] = $uinfo['weightbegin'];
                    $posts['weightnow'] = $uinfo['weightnow'];
                    $posts['weightend'] = $uinfo['weightend'];
                    $posts['sygn'] = $uinfo['sygn'];
                    
                }
	}

	return $posts;
}

Bez Smarty skrypt functions.php działa już sobie dobre pół roku. W czym leży problem?
0

Zrób var_dump($data).

0
array(12) { [1]=> array(10) { ["id"]=> string(2) "60" ["user"]=> string(1) "3" ["date"]=> string(19) "2011-09-18 15:59:01" ["content"]=> string(30) "

To jest testowy post...
" ["description"]=> string(29) "

To jest testowy podpis
" ["lastmodify"]=> string(19) "0000-00-00 00:00:00" ["name"]=> string(7) "jola131" ["postcount"]=> int(1) ["avatar"]=> string(12) "avatar/j.jpg" ["lastenter"]=> string(19) "2011-07-03 19:07:36" } ["weightbegin"]=> string(2) "90" ["weightnow"]=> string(2) "59" ["weightend"]=> string(2) "54" ["sygn"]=> string(1) "2" [2]=> array(10) { ["id"]=> string(2) "63" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } [3]=> array(10) { ["id"]=> string(2) "64" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } [4]=> array(10) { ["id"]=> string(2) "65" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } [5]=> array(10) { ["id"]=> string(2) "66" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } [6]=> array(10) { ["id"]=> string(2) "67" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } [7]=> array(10) { ["id"]=> string(2) "61" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } [8]=> array(10) { ["id"]=> string(2) "62" ["user"]=> string(1) "1" ["date"]=> string(19) "2011-09-18 16:09:52" ["content"]=> string(22) "

Testowa treść
" ["description"]=> string(22) "

Testowa treść
" ["lastmodify"]=> string(19) "2011-09-18 16:10:06" ["name"]=> string(7) "MaHanka" ["postcount"]=> int(7) ["avatar"]=> string(24) "avatar/earthday10-hp.gif" ["lastenter"]=> string(19) "2011-07-03 19:07:10" } }

Dane w porządku...

0

Weź to w <pre> wrzuć, bo nic nie widać. Array(12) znaczy, że tablica ma 12 elementów, chyba powinna mieć 1? Dlaczego indeksujesz ją od 1? W PHP tablice indeksowane są od 0.

0
$posts[$i]['postcount'] = UserPostCount($c[1]);
$posts[$i]['avatar'] = $uinfo['avatar'];
$posts[$i]['lastenter'] = $uinfo['lastenter'];
$posts['weightbegin'] = $uinfo['weightbegin'];
$posts['weightnow'] = $uinfo['weightnow'];
$posts['weightend'] = $uinfo['weightend'];
$posts['sygn'] = $uinfo['sygn'];

jeezz... <facepalm> :D
Niech żyje Ctrl + C Ctrl + V!

1 użytkowników online, w tym zalogowanych: 0, gości: 1