d3d!k Smarty n00b
Joined: 23 Nov 2008 Posts: 1
|
Posted: Tue Dec 23, 2008 6:26 pm Post subject: Problemy z petlami... |
|
|
Witam, mam następujący kod:
Code: | $catdata = $db->cache('read', 'cat_data');
$cat_id = $db->cache('read', 'cat_data_id');
if (!$catdata || !$cat_id)
{
$sql = "SELECT cat_id, cat_title, cat_desc, cat_order FROM " . CATEGORIES_TABLE . " ORDER BY cat_order DESC";
$result = $db->query($sql);
while ($row = $db->fetch($result))
{
$catdata[] = Array(
'id'=>$row[cat_id],
'desc'=>$row[cat_desc],
'name'=>bbcode($row[cat_title])
);
$cat_id[] = $row[cat_id];
}
$db->cache('write', 'cat_data', $catdata);
$db->cache('write', 'cat_data_id', $cat_id);
}
for($i=0; $i<count($cat_id); $i++)
{
$sql = "SELECT f.*, t.topic_id, t.topic_title, t.topic_desc, t.topic_time, t.topic_poster, u.user_id as user_id_topic, u.user_username as username_topic, u2.user_id as user_id_post, u2.user_rank as user_rank, u2.user_username as username_post, u2.user_rank as user_2rank, p.post_id, p.post_subject, p.post_text, p.poster_id, p.post_time, p2.topic_id, p2.post_text as topic_text
FROM ((((( " . FORUMS_TABLE . " f
LEFT JOIN " . TOPICS_TABLE . " t ON t.topic_id = f.forum_last_topic_id )
LEFT JOIN " . POSTS_TABLE . " p2 ON p2.topic_id = f.forum_last_topic_id )
LEFT JOIN " . POSTS_TABLE . " p ON p.post_id = f.forum_last_post_id )
LEFT JOIN " . USERS_TABLE . " u ON u.user_id = t.topic_poster )
LEFT JOIN " . USERS_TABLE . " u2 ON u2.user_id = p.poster_id )
WHERE f.cat_id = '".$cat_id[$i]."' AND f.parent_id = 0 ORDER BY f.forum_order";
$result = $db->query($sql);
while ($row = $db->fetch($result))
{
$forumdata[$i][] = Array(
'id'=>$row[forum_id],
'cid'=>$row[cat_id],
'name'=>bbcode($row[forum_name]),
'posts'=>$row[forum_posts],
'topics'=>$row[forum_topics],
'desc'=>bbcode($row[forum_desc]),
'username_topic'=> security($row[username_topic]),
'color_username_topic'=> color_username($row[user_id_topic],security($row[username_topic]),$row[user_rank]),
'topic_id'=>$row[topic_id],
'topic_name'=>substr(bbcode($row[topic_title]), 0, 24) . ((strlen(bbcode($row[topic_title])) > 24) ? ',,,' : ''),
'topic_desc'=>bbcode($row[topic_desc]),
'topic_text'=> substr(bbcode($row[topic_text]), 0, 260) . ((strlen(bbcode($row[topic_text])) > 260) ? '...' : ''),
'topic_time'=>date('d/m/y, H:i', $row[topic_time]),
'username_post' => security($row[username_post]),
'color_username_post' => color_username($row[user_id_post],security($row[username_post]),$row[user_2rank]),
'post_id'=>$row[post_id],
'post_subject'=>substr(bbcode($row[post_subject]), 0, 24) . ((strlen(bbcode($row[post_subject])) > 24) ? ',,,' : ''),
'post_text'=> substr(bbcode($row[post_text]), 0, 260) . ((strlen(bbcode($row[post_text])) > 260) ? '...' : ''),
'post_time'=>date('d/m/y, H:i', $row[post_time]),
);
}
}
$template_tpl->assign("forumdata", $forumdata);
$template_tpl->assign("catdata", $catdata); |
i chciałbym teraz zrobić pokazywanie subfor dla danych for, robie wszystko wedlug schematu i nie działa ma ktoś może jakiś pomysł ? :/
Proszę o odpowiedź |
|