Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:12:04+00:00 2026-06-18T08:12:04+00:00

I am involved in the development of a CMS at work using PL/SQL and

  • 0

I am involved in the development of a CMS at work using PL/SQL and an Oracle DB and I wish to replicate the same sort of structure for my own CMS using PHP and MySQL. I’m a PHP programmer from the old procedural days and i’m now trying to get to grips with OOPHP.

I have three tables. One represents a page. Another represents the templates that can be used within a page and the other represents the content. I’ve got as far as outputting the header and footer of the page (which are stored within the page table) however I now need to populate the page with content. To do this, I need to query the template table and assign the html code to a variable. I then need to use the content table to replace specific tags in the html code that is assigned to the variable (from the templates table) with the content from another table. So, for example:

I query the template table and pull out a column which contains a html structure. Within this structure there are self-generated tags such as [i1] [i2] [i3] which relate to columns in the content table. What I am aiming to do is replace these tags with the relevant contents of each relevant column in the content table (so [i1] would be replaced with the content from the i1 column in the relevant row. There can be multiple entries in the content table for each page so these are ordered by sequence.

I’m currently stuck at pulling an array of all content that is relevant to the specific page from the content table. I know how to do this procedurally using the old mysql interface but I can’t find any recent posts as to how to do it properly in mysqli. Any tips?

Here is my current set of classes:

class Connection extends Mysqli{

    public function __construct($mysqli_host,$mysqli_user,$mysqli_pass, $mysqli_db) {
        parent::__construct($mysqli_host,$mysqli_user,$mysqli_pass,$mysqli_db);
        $this->throwConnectionExceptionOnConnectionError();     
        $this->getUser();
    }

    private function throwConnectionExceptionOnConnectionError(){

        if(!$this->connect_error){
            echo "Database connection established<br/>";
        }else{
        //$message = sprintf('(%s) %s', $this->connect_errno, $this->connect_error);
            echo "Error connecting to the database."; 
        throw new DatabaseException($message);
        }
    }
}

class DatabaseException extends Exception{

}

class Page {

    public function __construct() {
        if(isset($_GET['id'])){
            $id = $_GET['id'];
        }else{      
            $id = 1;
        }       
        get_headers($id);
        get_content($id);
        get_footer($id);
    }

    private function get_headers($pageId){ 
        $retrieveHead = $this->prepare("SELECT header FROM pages WHERE page_id=?");
        $retrieveHead->bind_param('i',$pageId);
        $retrieveHead->execute();
        $retrieveHead->bind_result($header);
        $retrieveHead->fetch();
        $retrieveHead->close();
        echo $header;   
    }

    private function get_footer($pageId){ 
        $retrieveFooter = $this->prepare("SELECT footer FROM pages WHERE page_id=?");
        $retrieveFooter->bind_param('i',$pageId);
        $retrieveFooter->execute();
        $retrieveFooter->bind_result($footer);
        $retrieveFooter->fetch();
        $retrieveFooter->close();
        echo $footer;   
    }

    private function get_content($pageId){
        $retreiveContent = $this->prepare("SELECT * FROM content WHERE page_id=? ORDER BY sequence");
        $retreiveContent->bind_param('i',$pageId);
        $retreiveContent->execute();
    }

}

From what I can remember of mySQL, from here I would do a for loop but how would I go about doing this using this OOP approach and how would I then go about conducting the replacement of tags for each template?

My table structure can be found below. Hopefully this will make it more clear what I am looking for:

Table Structure

I’m guessing that in some way my query could be adapted to perform an inner join so that the code column from the templates table is also retreived but I’ve not really used joins with MySQLi before so I’m not sure if there is a specific way to write the syntax.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:12:05+00:00Added an answer on June 18, 2026 at 8:12 am

    With Jim’s help I have come up with the definitive solution:

        private function get_content($pageId){
             $retreiveContent = $this->prepare("SELECT template_id, section_title, i1, i2 FROM content WHERE page_id=? ORDER BY sequence");
             $retreiveContent->bind_param('i',$pageId);
             $retreiveContent->execute();
             $retreiveContent->bind_result($template_id, $section_title, $i1, $i2);
                while ($retreiveContent->fetch()) {
                //Variables will be populated for this row.
                //Update the tags in the template.
             $theTemplate = grabTheTemplate($template_id);
             $theTemplate = str_replace('[i1]',$i1,$theTemplate);
             $theTemplate = str_replace('[i2]',$i2,$theTemplate);
             //$theTemplate is populated with content. Probably want to echo here
            echo $theTemplate;
        }
    
    
    }
    

    As there can be multiple content items on a single page each of which could have a different template, I have moved the grabTheTemplate function call inside of the while loop so that the value from the template_id column can be used to retrieve the relevant template. I haven’t tried this on my test server yet but in theory it should all work. I will try it this evening and edit this post if there are any bugs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently involved in the development of a software using distributed computing to
I'm involved in a development project that is using freeglut (based on the long
Currently my development environment is using SQL server express 2008 r2 and VS2010 for
I am using an SVN repository for my web development work. I have a
I am involved in the development of a WPF Prism application which uses the
My team does some development, but is mainly involved in supprting an existing suite
What are the 'costs' involved in calling an empty PHP function? The main purpose
I am currently involved in the development of a large rails application that interfaces
Lets say that you get involved in the development of a large project that
I am trying to get involved in XNA game development (most likely for Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.