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 8217739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:33:21+00:00 2026-06-07T12:33:21+00:00

I am currently working on this website , and i need some help regarding

  • 0

I am currently working on this website, and i need some help regarding php and ajax.
I apologise if this is a simple fix, but i’ve looked everywhere and i can’t find the solution.

Anyway, the links on the left load content on the right with ajax. That’s the easy part.
The sublinks under ‘gallery’ load a php file like this:

<?php
include "connect_to_mysql.php";
include_once("classes/category.class.php");
include_once("classes/album.class.php");
include_once("classes/images.class.php");
$category = new category();
$categories = $category->loadAbstract();
?>
<div id="image_gallery">
<?php 
foreach ($categories as $category) {
    if ($category->hasAlbums()) {
        foreach ($category->albums as $album) {
            echo '<div class="album_container">';
                echo '<div class="sublinks" onClick="loadAlbum(\''.$album->getId().'\')">
                        <h4>'.$album->getName().'</h4>
                    </div>';
        }
    }
}
?>
</div>
<script>
    function loadAlbum(Id) {
        $.ajax({
            type: 'POST',
            url: 'loadalbum.php',
            data: "selectedAlbum="+Id,
            success: function(result) {
                        $("#"+Id).html(result);
                    }
        });
</script>

Obviously, this calls loadalbum.php, which i have to add the same includes:

<?php 
include "connect_to_mysql.php";
include_once("classes/category.class.php");
include_once("classes/album.class.php");
include_once("classes/images.class.php");
$selectedAlbum=$_POST['selectedAlbum'];
?>

The problem is that every time i select a different category on the left, it has to call these classes, and then when an album is selected from that category, the classes are called again. This is slowing down the load time considerably as it has to keep retrieving data from the database.

I use a bit of javascript to stop it from loading an album if it has already been loaded, but as soon as a different link is selected on the left, it goes back to square one.

Is there a way to load all of my classes when the web page opens and then reference them when my php files are loaded through ajax?

Thanks in advance!

  • 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-07T12:33:22+00:00Added an answer on June 7, 2026 at 12:33 pm

    I think you need to redefine your entity relationships. Based on your code: category, album, and image all have equal standing. I don’t think that is true, but it’s not my design. At any rate, include your models into your controller class

    <?php
    require_once "classes/album.class.php";
    require_once "classes/category.class.php";
    require_once "classes/images.class.php";
    
    class Controller
    {
      public $album;
      public $image;
      public $category;
    
      public function __construct()
      {
       $this->album = new Album();
       $this->image = new Image();
       $this->category= new Category();
      }
    
      public invoke(){
        $categories = $this->category->loadAbstract();
        include "path-to-gallery.php";
      }
    }
    

    So now within your controller, you have access to all your models. Put your data manipulation functions inside your model classes and call them from the controller. The included page will be preloaded with the $categories data. You can then loop through it in the view.

    Two important notes: 1) Require files that MUST exist at runtime. You’ll get a fatal error if they don’t. An include will only give a warning, which may be suppressed, and 2) requires and includes are language constructs, not methods. Parentheses are unnecessary.

    I’ve provided a basic outline for your controller class. My way is just one of hundreds of other MVC implementations. Many will argue the finer points of what I wrote. Don’t worry about it. Just try to understand the basics of what I provided. If it helps, great. Be sure to accept the answer. If not, then ignore it.

    Good luck.

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

Sidebar

Related Questions

I'm currently working on my own PHP Framework, and I need some help figuring
I have a working website, where I use this expression everywhere. price.ToString(C) It currently
I currently have this working but it requires me to have a static method
I am currently working on a project / website and I will need to
Okay, I am stumped on this one and need some quick help. I have
I'm currently working on a quote retrieval system for my employer's website using mysql/php/html.
I'm currently working on an application where I need to do some manipulation of
I am currently working through this tutorial: Getting Started with jQuery For the two
I am currently working in this problem for hours now. I have to create
I am currently working on MGSplitViewController .So in this custom split view controller the

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.