SMARTY Two cycles of advice
This post was last edited by sky94132003 on 2014-08-06 03:20:32
All sections
@ $row _fid = "select * from ' Forum_forum ' ORDER by ' displayorder ' ASC";
$stmt = $pdo->prepare ($row _fid);
$stmt->execute ();
$row _forum = $stmt->fetchall (PDO::FETCH_ASSOC);
Topic category
foreach ($row _forum as $key = + $value) {
$fid = $value ["FID"];
@ $sql = "Select ' typeid ', ' name ' from ' forum_topic_type ' WHERE ' fid ' = $fid";
$stmt = $pdo->prepare ($sql);
$stmt->execute ();
$row _type = $stmt->fetchall (PDO::FETCH_ASSOC);
}
Print_r ($row _type);
$smarty-Assign ("All_forum", $row _forum);
The code is for you to see the logic, but it's not successful.
Learn to Smarty time is not long
There are two tables
Forum_forum is the discussion section ID is mainly ' name ', ' FID '
Forum_topic_type is the topic of the discussion section category ID is mainly ' typeid ', ' name ', ' FID '
would have
I was going to
Forum_forum lists all the sections and adds them to the Smarty assign
Success is displayed in the list of all the sections in the foreground
But under the name of the section, I want to cycle through all the "subject categories" in this discussion section.
But found that these things (this table Forum_forum) had been circulating in the foreground,
I can't get fid to loop related topic classifications because the ID of the loop result is already in the template to get
So I thought about it. Before Smarty's assign, try a foreach to see what the results are,
and try and see if you can merge into the same group, assign, and find it a little bad.
So I would like to ask you predecessors
The solution I've thought of
1. Merging multiple table queries, but also more than one topic category ... So just give up the method
2. Do a smarty plug-in, has been tried, but also stuck can't go forward
Actually smarty this sells two times the circulation question has been troubled for a long time, but seems unable to evade again, humbly consults, hoped thoroughly to understand this kind of question
Ask for advice!
------Solution--------------------
All sections
@ $row _fid = "select * from ' Forum_forum ' ORDER by ' displayorder ' ASC";
$stmt = $pdo->prepare ($row _fid);
$stmt->execute ();
$row _forum = $stmt->fetchall (PDO::FETCH_ASSOC);
Topic category
foreach ($row _forum as $key = + $value) {
$fid = $value ["FID"];
@ $sql = "Select ' typeid ', ' name ' from ' forum_topic_type ' WHERE ' fid ' = $fid";
$stmt = $pdo->prepare ($sql);
$stmt->execute ();
$row _forum[$key] [' list '] = $stmt->fetchall (PDO::FETCH_ASSOC);
}
Print_r ($row _forum);
$smarty-Assign ("All_forum", $row _forum);