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

  • SEARCH
  • Home
  • 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 8689259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:36:03+00:00 2026-06-12T23:36:03+00:00

I’m working on a comment/content/posting system and hit a fork in the road, so

  • 0

I’m working on a comment/content/posting system and hit a fork in the road, so I figured I should ask for other opinions before choosing a path. Sorry but at this time I don’t have a good enough working example to present (Or one that I can share) so hopefully my description is enough.

I have an index.php main page which calls loadmore.php to request user posts to display in a div. The loadmore.php gets this data from a MySQL DB.

Each post can be of different types and are displayed differently when put up on the screen.

Examples (All posts display the user that posted and the date on top):

  • POST: Regular post, text only.
  • LINK: Displays the title of the linked page as a hyperlink, small thumbnail image next to that, and a snippet of text below that was extracted from the linked site.
  • PICTURE: Displays large picture with caption below it.
  • VIDEO: Displays title on top, with video under the title taking half the width of the div, description of video is next to the video.

Don’t concern yourself with the formatting etc, I just wanted to show that each post will be formatted differently according to type of post and the HTML can be lengthy.

Now, THIS is what I want to know; WHERE should the generated, or chosen, HTML come from? (For simplicity, I’m using pseudo code)

Option 1. I could have the various HTML “template” in ajax/js on the index.php page itself and just fill in the variables using a bunch of IF statements, but I’m not sure this should be in the index file.

index.php

    <div id="mainContainer">
    //Content
    <div id="postsContainer">
        //Individual posts go in here (Several divs formatted according to content)
    </div>
    //More content
    </div>
    <script>
     GET data to loadmore.php and get results into variables
     IF "type" is "link" 
         append to #postsContainer "<div id="linkURL"....$variables etc...
     IF "type" is "video" 
         append to #postsContainer "<div id="videoDiv"....$variables
     //And so on...
    </script>

loadmore.php

    <?PHP
    //Get and process post data into variables
    //Query SQL database for more/new posts
    //Return individual data in JSON format to index.php
    ?>

Option 2. OR, I could have the loadmore.php use IF statements in order to return the appropriate HTML string to be prepended in index.php, but I find that it would be inefficient to pass so many long HTML strings between the 2 PHP files server-side when only the variables can be passed.

index.php (Note: only the script portion is different)

    <div id="mainContainer">
    //Content
    <div id="postsContainer">
        //Individual posts go in here (Several divs formatted according to content)
    </div>
    //More content
    </div>
    <script>
     //GET data to loadmore.php and get resulting HTML string
     //Append to #postsContainer the HTML string returned from loadmore.php
    </script>

loadmore.php

    <?PHP
    //Get and process post data into variables
    //Query SQL database for more/new posts
    IF "type" is "link" 
         $returnHTML = "<div id="linkURL....$variables etc...
    IF "type" is "video" 
         $returnHTML = "<div id="videoDiv....$variables
    //And so on...

    return $returnHTML; 
    //This is a single long string returned with all HTML formatted by loadmore.php
    //index.php simply has to Append the entire string into the div
    ?>

Which is the best route to go with this? And why?

Sorry if it seems messy, I’m still getting used to this site’s formatting methods…

  • 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-12T23:36:04+00:00Added an answer on June 12, 2026 at 11:36 pm

    When doing something similar in the past,

    I would simply have your loadmore.php iterate over the posts you’d like to display, determine the type, and echo the correct formatting.

    <?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
    //...
    $result = $mysqli->query($query);
    
    while ($row = $result->fetch_array(MYSQL_ASSOC)) {
      $count += 1;
      echo '<div id="post'.$count.'">';
      switch ($row['type']) {
        case 'POST':
          //POST format
          break;
        case 'LINK':
          //LINK format
          break;
        case 'PICTURE':
          //PICTURE format
          break;
        //...
        default:
          //default
      }
      echo '</div';
    }
    
    $result->free();
    $mysqli->close();
    ?>
    

    Then you could simply load the php page into a div. One way is to use jQuery:

    <script typ="text/javascript">
        $(document).ready(function(){
             $("#postsContainer").load("loadmore.php");
        });
    </script>
    

    If you wanted to pass parameters to loadmore.php (say from a form, perhaps hidden), you could use the following:

    var variables = $("#form").serialize();
    $.post("loadmore.php", variables, function(data) {
        $("#postsContainer").html(data);
    });
    

    Then, retrieving the posted data in loadmore.php is as simple as $POST_[‘variable’], and you could incorporate that into your query (or whatever else), depending on what you’re doing.

    I think just loading the output from a php file is better than transferring the variables and having templates and ifs bloating your webpage (option 1), or passing html strings from a php file (option 2).

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

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.