I am trying to create a simple platform in an MVC architecture.
This is my database setup (relevant part):
Table: Forums_graphics
`Forum_categories` (` Cat_id` INT (8) tap etanement, cat_title` VARCHAR (255) No NULL, `cat_desc` text no NULL, primary key (` cat_id`), unique key (`cat_title`)
Table: forum_topics
`forum_topics` (` topic_id` INT (8) No NULL AUTO_INCREMENT, `cat_id` INT (8) No NULL comment,` user_id` INT (11 'Foreign key with forum_categories table') No zero comment, `topic_title` VARCHAR (255) No NULL,` topic_desc` no text NULL, `topic_date` DATETIME default zero, primary key (` topic_id`), foreign key (`cat_id`) reference 'foreign key with table of them'
example < / Strong> For functionality, I would like to get:
Categ is 1 in cat_id = 1
Cat_id = 1 in topic 1. cat_id = 2 in topic 2
Now when Category 1 is selected, I want to show only 1 topic.
If Category 2 is selected, then I want to show only 2 topics.
This generated SQL statement is that:
from select * stmnt ready from forum_categories fccat.css_id = ft.cat_id where fc.cat_id = forum_topics foot Join? Feet by order. DCC 'DCC'; SET @ A = 1; EXECT STMnt USE @ A; My Problem : I would like to move this functionality into my PHP MVC structure.
This is my endeavor, which is not work (it shows all topics in all categories).
Controller / ** * Show all topics in the selected category * / Public Function ShowFomTix () {$ Topic_model = $ this-> LoadModel ('Forum'); $ This- & gt; View- & gt; Forum_tacks = $ theme_model- & gt; GetForumTopics (); $ This- & gt; View-> Presenting ('forum / viewTopics'); }
model
/ ** * A array containing all forum topics in the database * Each array element is an object, in which the subject There is data. * @return array all platform topics * / public function getForumTopics ($ cat_id) {$ sql = 'select * from fccat_id = ftcat_id = ft.cat_id forum_topics foot join fc fccat_id =: order by ft.topic_date Cat_id DESC '; $ Query = $ this- & gt; Db- & gt; Ready ($ sql); $ Query-> Execute (array: (': cat_id' = & gt; $ cat_id)); Return $ query- & gt; Fatch ALL (); }
if ($ this-> forum_pextics) {foreach ($ this-> $ keyboard = as form_packets & gt; ; $ Value) {echo '& lt; P & gt; & Lt; Strong & gt; Title: & lt; / Strong> . $ Value- & gt; Subject-Title '& lt; / P & gt; '; Echo & lt; P & gt; & Lt; Strong & gt; Details: & lt; / Strong> '$ Value- & gt; Topic_desc '& lt; / P & gt; '; Echo & lt; P & gt; & Lt; Strong & gt; Author: & lt; / Strong> '$ Value- & gt; Subject_members' & lt; / P & gt; '; Echo & lt; P & gt; & Lt; Strong & gt; Date: & lt; / Strong> '$ Value- & gt; Topic_date '& lt; / P & gt; '; }} Else {echo 'no forum topic'. '; }
Support will be highly appreciated! Thanks !!
For example, your page should be your code
Controller
Public Function Showtropics () {$ default_category = 1; $ Topic_model = $ this- & gt; LoadModel ('Forum'); $ Cat_id = isset ($ _GET ['cat_id'])? $ _GET ['cat_id']: $ default_category; $ This- & gt; View- & gt; Forum_tacks = $ theme_model- & gt; GetForumTopics ($ cat_id); $ This- & gt; View-> Presenting ('forum / viewTopics'); }
model
public function getForumTopics ($ cat_id) {$ sql = 'select * from fccat_id = foot forum_topics foot on forum_categories Ho fc Cat_id WHERE fc.cat_id =: cat_id command ft.topic_date DESC '; $ Query = $ this- & gt; Db- & gt; Ready ($ sql); $ Query-> Execute (array: (': cat_id' = & gt; $ cat_id)); Return $ query- & gt; Fatch ALL (); }
if ($ this-> forum_pextics) {foreach ($ this-> $ keyboard = as form_packets & gt; ; $ Value) {echo '& lt; P & gt; & Lt; Strong & gt; Title: & lt; / Strong> . $ Value- & gt; Subject-Title '& lt; / P & gt; '; Echo & lt; P & gt; & Lt; Strong & gt; Details: & lt; / Strong> '$ Value- & gt; Topic_desc '& lt; / P & gt; '; Echo & lt; P & gt; & Lt; Strong & gt; Author: & lt; / Strong> '$ Value- & gt; Subject_members' & lt; / P & gt; '; Echo & lt; P & gt; & Lt; Strong & gt; Date: & lt; / Strong> '$ Value- & gt; Topic_date '& lt; / P & gt; '; }} Else {echo 'no forum topic'. '; }
Comments
Post a Comment