hi
i would like to do like this
+2007
+2008
-2009
+BCA-I
+BCA-II
-BCA-III
Advance Web PRogramming.pdf
JAVA.pdf
OB.pdf
+PGDCA
+M.Sc.
+2010
like this code i want as when user click on + then open like 2009 example and open classes like BCA etc. and after click on bca than open papername if we click on paper than open a pdf file.
all these things maintain from database. please suggest me database structure and php code to do this type code.
thanks in advance
with php mysql

Dani AI

Generated

asked for a database-driven tree (years → classes → papers → PDF) that expands on + clicks. and were right that the UI is best handled with client-side JS (jQuery) while PHP provides node data. Below is a compact, practical pattern: one adjacency-list table, a single AJAX endpoint that returns children as JSON, and a tiny client script that lazy-loads nodes.

A simple schema (adjacency list):

CREATE TABLE nodes (
  id INT AUTO_INCREMENT PRIMARY KEY,
  parent_id INT DEFAULT 0,
  name VARCHAR(255) NOT NULL,
  type ENUM('year','class','paper','file') NOT NULL,
  file_path VARCHAR(512) DEFAULT NULL,
  sort_order INT DEFAULT 0,
  INDEX (parent_id)
);

Backend: single endpoint that returns children for a given parent_id (use PDO and prepared statements):

<?php
// get_children.php?parent_id=...
$parent = isset($_GET['parent_id']) ? (int)$_GET['parent_id'] : 0;
$pdo = new PDO('mysql:host=...;dbname=...', 'user', 'pass', [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare(
  'SELECT n.id,n.name,n.type,n.file_path,
   (SELECT COUNT(*) FROM nodes n2 WHERE n2.parent_id = n.id) AS has_children
   FROM nodes n WHERE parent_id = :p ORDER BY sort_order,name'
);
$stmt->execute([':p'=>$parent]);
header('Content-Type: application/json');
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));

Frontend (minimal jQuery lazy-load pattern — use an existing tree plugin for polish):

$(document).on('click','.expand',function(){
  var li = $(this).closest('li'), id = li.data('id');
  if(li.data('loaded')) { li.children('ul').toggle(); return; }
  $.getJSON('get_children.php',{parent_id:id},function(items){
    var ul = $('<ul/>');
    items.forEach(function(it){
      var node = $('<li/>').attr('data-id',it.id)
                .append(it.has_children?'<span class="expand">[+]</span>':'')
                .append('<span class="title">'+$('<div/>').text(it.name).html()+'</span>');
      if(it.type==='file') node.append(' <a href="'+it.file_path+'" target="_blank">open</a>');
      ul.append(node);
    });
    li.append(ul).data('loaded',true);
  });
});

Notes: always validate/sanitize file_path and serve files via a controlled script to prevent traversal; index parent_id for performance; use lazy-loading for large trees; add access checks and caching for scalability. This fills the gap between the UI suggestions in earlier replies and a concrete DB+PHP workflow.

Recommended Answers

All 3 Replies

You want to make linked dropdown button???
which will respond according to the rest drop down button???

Check this...

Member Avatar for Member #120589

I agree with vib, this is a js matter. jQuery has loads of examples treeview, jtree etc. You can create the jscode dynamically with php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.