SMARTY two cycles, please.

Source: Internet
Author: User
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);
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.