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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:36:18+00:00 2026-06-08T19:36:18+00:00

Hey guys I have the following sample. I have navigation which is loaded from

  • 0

Hey guys I have the following sample. I have navigation which is loaded from an mySQL databse with an PHP file called getNavi.php:

$query="SELECT * FROM projects WHERE category=\"$category\"";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

while ($row = mysql_fetch_object($result)) {
    $title=$row->title;
    $id=$row->id;
    echo "<div class=\"sublink\" data-subsite=\"$id\" data-category=\"$category\" data-title=\"$title\" ><a href=\"#\">$title<br />";
}

These links are loaded correctly and are handled via AJAX:

$(document).ready(function(){
    $('.link').click(function(){
        var subsite = $(this).data('subsite');
        $('#naviLeftContent').load('php/getNavi.php?category='+subsite);
    });
    $(document).on("click", ".sublink", function(){
        var subsite = $(this).data('subsite');
        var category = $(this).data('category');
        var title = $(this).data('title');
        var info = category + "/" + title;
        var lower = info.toLowerCase();
        var nospaces = lower.split(' ').join('');
        $('#titleContent').text(title);
        $('#imageContent').load('php/getImages.php?info='+nospaces);
        $('#textContent').load('php/getText.php?id='+subsite);
        $('#infosContent').load('php/getInfos.php?id='+subsite);
    });
});

And this part is where it starts to get buggy, because the content of my divs is sometimes only partially loaded or not at all. The Text is not cut, but mostly the title and the infos are not loaded. And sometimes it occures that the infos toggle while i repeat click on the same link all the time.

The problem is that in all PHP files I load I open and close a SQL connection.
Now as a Java programmer I thought it would be nice to create a class for my connection with member functions, which I could call. Of course I thought of an singleton object, but I don’t know how to call the methods when I would create a PHP file like this:

<?php
class DBConnection {

  private static $instance;

  private function __construct() {
    $user="root";
    $password="";
    $database="klb";
    mysql_connect("localhost",$user,$password);
    @mysql_select_db($database) or die( "Unable to select database");  
 }

  public function __destruct() {
      mysql_close();
 }

  public static function getInstance() {

    if(!self::$instance) {
      self::$instance = new self();
    }

    return self::$instance;
  }

  public function getNaviForCategory($category) {
    $query="SELECT * FROM projects WHERE category=\"$category\"";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    while ($row = mysql_fetch_object($result)) {
        $title=$row->title;
        $id=$row->id;
        echo "<div class=\"sublink\" data-subsite=\"$id\" data-category=\"$category\" data-title=\"$title\" ><a href=\"#\">$title<br />";
    }
  }

 public function getInfosForProject($id) {
    $query="SELECT * FROM projects WHERE id=\"$id\"";
    $result=mysql_query($query);
    $num=mysql_numrows($result);

    while ($row = mysql_fetch_object($result)) {
        $infos=$row->info;
        echo $infos;
    }
  } 

   private function createTableProjects(){
        $query="CREATE TABLE projects (id int(6) NOT NULL auto_increment,category varchar(30) NOT NULL,title varchar(30) NOT NULL,
        info varchar(200) NOT NULL,text varchar(8000) NOT NULL,PRIMARY KEY (id),UNIQUE id (id))";
        mysql_query($query);
   }
}

?>

I now need some replacement for this lines of code:

$('#infosContent').load('php/getInfos.php?id='+subsite);

EDIT :

I solved this problem with the following code:

<?php
require_once( 'dbconnection.php');
$category = $_GET["category"];
DBConnection::getInstance()->getNaviForCategory($category);
?>

But it seems that my on click listener for the sublink divs (which is mentioned above) not always pass the right variables to the php code.

 $('#titleContent').text(title);

This line of code for example only works if I choose another category.

  • 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-08T19:36:20+00:00Added an answer on June 8, 2026 at 7:36 pm

    may be in getNavi.php instead old code

    $category = intval($_GET['category']);
    DBConnection::getInstance()->getNaviForCategory($category);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I have an assigned array from mysql results and I simply want
Hey you guys (and girls), I have implemented the following CSS: #tab-navigation ul li:last-child
Hey guys, I'm just starting out with MySQL and PHP and have a question.
Hey guys I have the following while loop which seems not to stop. It's
Hey guys I have the following code working which is sending a GET Request
Hey guys in my iptables file I have the following line: -A INPUT -m
Hey Guys, i have created the following Menu Structure: <div id=menu> <ul> <li><a href=#>Main
Hey guys i have a question which i have been looking for the answer
Hey guys, I have the following HTML structure that I am trying to pull
Hey guys. I have the following situation. I want to use a TypeDescriptor to

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.