PHP - Cms Crud Tree/recursive Menu
Hello my good people
I'm doing a content manager system in PHP and mySQLi, following a serie of video tutorials.
But in my project I am using a tree menu.
In the front office all works smoothly (the tree menu displays all results - menu and submenus - and each button carries the information of the respective page).
Similar TutorialsI have a database table with categories and subcategories, with the structure of :: categoryid, categoryname, parentid I have found numerous examples of printing out a tree structure of the table, and it works, but I would like to get all the data into an array, ultimately to print the array to a listbox to select from. The array structure would be categoryid => categoryname. The basic query I have now is as follows :: Code: [Select] function createCatTree($thisParentCatID=0,$depth=0) { $catIDQ = mysql_query("SELECT * from category WHERE parentcatid = $thisParentCatID;"); while ( $catIDQRow = mysql_fetch_array($catIDQ) ) { $thisCatName = $catIDQRow['categoryname']; $thisCatID = $catIDQRow['categoryid']; for($i = 0; $i < $depth; $i++) $spcstr.= " "; // create spaces to mimic a tree structure $value = $spcstr.$thisCatName; // add spaces echo $value; createCatTree($thisCatID,$depth+1); } } I was hoping to send the categoryid and categoryname to an array, like Code: [Select] $arr[$thisCatID] = $value;then change my function call to be Code: [Select] createCatTree($thisCatID,$depth+1,$arr);to send the array as a variable back to the function to hold the data going forward. Also, I added a section at the top of the function to see if the array needed to be initialized, like Code: [Select] if ($arr == "") { $arr = array(); } but this does not work. Is there any way to use this basic recursive code and save all the data to an array to be worked on at a later time? Hi consider I have following type of directory structure inside /root folder1 -fileName1.1 -folder1.2 --fileName1.2.1 $dirItr = new RecursiveDirectoryIterator('/root'); $itr = new RecursiveIteratorIterator($dirItr); $structure ; // the type of structure i want to build store inside it foreach($itr as $object) { //magic happens here } //in the end I want folowing type of structure $structure = array('label'=>'folder1','children'=>array(array('label'=>'fileName1.1'),array('label'=>'folder1.2','children'=>array(array('label'=>'fileName1.2.1'))))); Importan observations; a)children key is an array which contains arrays of other folder or filename; b) filename does not have children attribute because they are leafs of tree c) a folder without any files will be represented as array('label'=>'emptyFolderName',children=>array()) ; //children attribute with empty array. I wd be really thankfull to the user whoever solved this problem , wasted a month already on it !! thanks in Advance. Can somebody please have a look at this. The Problem I am having is that only 1 entry for each month goes into the tree and for the life of me I can't figure out why. Code: [Select] $queryyp = "SELECT YEAR(date) as year, MONTHNAME(date) as month, title FROM monsterpost ORDER BY date DESC"; // query to get the rows you want in the order that you want them, with the year and monthname specifically selected as well $resultyp = mysql_query($queryyp); $last_heading = null; // remember the last heading (initialize to null) while($rowyp = mysql_fetch_assoc($resultyp)){ $new_heading = $rowyp['year']; // get the column in the data that represents the heading $new_subheading = $rowyp['month']; // get the column in the data that represents the subheading if($last_heading != $new_heading){ // heading changed or is the first one $last_heading = $new_heading; // remember the new heading $last_subheading = null; // (re)initialize the subheading // start a new section, output the heading here... echo "<ol class=\"tree\"><li><label for=\"folder1\">{$rowyp['year']}</label> <input type=\"checkbox\" id=\"folder1\" /></li></ol>"; } // subheading under each heading if($last_subheading != $new_subheading){ // subheading changed or is the first one $last_subheading = $new_subheading; // remember the new subheading // start a new section, output the subheading here... echo "<ol><li><label for=\"subfolder1\">{$rowyp['month']}</label> <input type=\"checkbox\" id=\"subfolder1\" />"; } // output each piece of data under a heading here... echo "<ol><li class=\"file\">{$rowyp['title']}</li></ol></li></ol></li></ol>"; } Ok. I am trying to create a customer tracking database that will allow me to get a handle on my customer support inquiries. To do this I have created a database that will store all of a customers pertinent information and then I plan on creating another table that will be 'Notes' where each note is associated with a customerID. I have created the form fine where I can input the data into the table but I am having issues with the next part. I would like to have a list/menu that will display all of the current users in the database. Then when I click on one of those it will display that information in the form so that I can view it, edit it, or delete it. But I have been stumped for multiple days and other php forums have been absolutely worthless. I know that php can pass a variable name in the address but I have no idea how to do that or how to use it when it's in the address. I know I'm a newb. Please help. I really need to move on from this hurdle. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <link href="maxxTraxx.css" rel="stylesheet" type="text/css" /> </head> <body> <?php //Load Database Connectivity and Form Helpers require 'DB.php'; require 'formhelper.php'; //Connect To Database $db = MY CONNECTIVITY IS FINE, HIDING FOR SECURITY PURPOSES if (DB::isError($db)) { die("Cant connect: " .$db->getMessage()); } //Print Message and Quit on Future Database Errors $db->setErrorHandling(PEAR_ERROR_DIE); customerList(); //Main Page Logic if ($_POST['_submit_check']) { foreach($_POST as $key=>$value) { if($key == 'saveCustomer') { //If validate_form() returns errors, show them the form with errors if ($form_errors = validate_formCustomer()) { show_form($form_errrors); } else { //The submitted data is valid, so process it process_formCustomer(); } } if($key =='go') { print $_POST['customerList']; } } }else { //The form wasn't submitted, so display it blank show_form(); } //------------FUNCTIONS--------------------------------------------------------- function show_form($errors = '') { //If the form is submitted, get defaults from submitted parameters if ($_POST['_submit_check']) { $defaults = $_POST; } else { //Otherwise set your own defaults $defaults = ''; } //If errors were passed in, put them in $error_text (with HTML markup) if ($errors) { $error_text = '<tr><td>You need to correct the following errors: '; $error_text .= '</td></tr><ul><li>'; $error_text .= implode('</li><li>',$errors); $error_text .= '</li></ul></td></tr>'; } else { //No errors? Then $error_text is blank $error_text = ''; } $states = array('AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY', 'Canada', 'Puerto Rico', 'Australia'); $status = array(1=>'Fine', 2=>'Received', 3=>'In Repair', 4=>'Waiting', 5=>'Shipped'); $months = array(1=>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May', 6=>'June', 7=>'July', 8=>'August', 9=>'September', 10=>'October', 11=>'November', 12=>'December'); $days = array(); for($i = 1; $i <=31; $i++) { $days[$i] = $i; } $years = array(); for($year = date('Y') , $max_year = date('Y')+5; $year < $max_year; $year++) { $years[$year] = $year; } //Jump out of PHP mode to make displaying all the HTML tags easier but still inside the show_form function ?> <div class="customerForm"> <center><h2>Customer Form</h2></center> <form method="post" action="<?php print $_SERVER['PHP_SELF']; ?>"> <table> <?php print $error_text ?> <tr><td>Last Name</td> <td><?php input_text('customerNameLast', $defaults); ?>, </td> <td>First Name</td> <td><?php input_text('customerNameFirst', $defaults); ?></td> <td>Phone Number</td> <td><?php input_text('customerPhone', $defaults); ?></td></tr></table> <table><tr><td>Address</td> <td><?php input_text('customerAddresss', $defaults); ?></td> <td>City</td> <td><?php input_text('customerCity', $defaults); ?></td> <td>State</td> <td><?php input_select('customerState', $defaults, $states); ?></td> <td>Zip</td> <td><?php input_text('customerZip', $defaults); ?></td></tr></table> <table><tr><td>Email</td> <td><?php input_text('customerEmail', $defaults); ?></td> <td>RMA #</td> <td><?php input_text('customerRMA', $defaults); ?></td> <td>Parts Out</td> <td><?php input_text('customerPartsOut', $defaults); ?></td></tr></table> <table><tr><td>Status</td> <td><?php input_select('customerStatus', $defaults, $status); ?></td> <td>Due Date</td> <td><?php input_select('customerDueMonth', $defaults, $months); ?> <?php input_select('customerDueDay', $defualts, $days); ?> <?php input_select('customerDueYear', $defaults, $years); ?></td></tr></table> <center><?php input_submit('saveCustomer', 'Save Customer'); ?></center> <input type="hidden" name="_submit_check" value="1"/> </form> </div> <?php }//End of the show_form() function function validate_formCustomer() { $errors = array(); return $errors; } function process_formCustomer() { global $db; //Get a unique ID for Customer $customerID = $db->nextID('customerID'); $customerDueDate = $_POST['customerDueYear'].'-'.$_POST['customerDueMonth'].'-'.$_POST['customerDueDay']; $db->query('INSERT INTO Customer (customerID, customerNameLast, customerNameFirst, customerPhone, customerEmail, customerAddress, customerCity, customerState, customerZip, customerStatus, customerPartsOut, customerRMA, customerDueDate) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)', array($customerID, $_POST['customerNameLast'], $_POST['customerNameFirst'], $_POST['customerPhone'], $_POST['customerEmail'], $_POST['customerAddress'], $_POST['customerCity'], $_POST['customerState'], $_POST['customerZip'], $_POST['customerStatus'], $_POST['customerPartsOut'], $_POST['customerRMA'], $customerDueDate)); //Tell the user that we adde a customer print '<center>Added '.htmlentities($_POST['customerNameLast']) .' to the database.</center> <br /><br />'; print '<center><a href="/maxxTraxx/index.php">Back To The Admin</a></center>'; }//End of process_formCustomer function function customerList() { global $db; $qCustomers = $db->query('SELECT customerID, customerNameLast, customerNameFirst FROM Customer'); print '<div class="customerList"><form action="test.php" method="get">'; print '<select name="customerList" size="30">'; while($row = $qCustomers->fetchRow()) { $qAllCustomers[0] = $row[0]; $qAllCustomers[1] = $row[1]; $qAllCustomers[2] = $row[2]; //print $row[0]; //print 'Customer #'.$qAllCustomers[0].' is: '.$qAllCustomers[2].' '.$qAllCustomers[1].''; print '<option value="'.$qAllCustomers[0].'" selected>'.$qAllCustomers[1].', '.$qAllCustomers[2].'</option>'; } print '</select></form></div>'; echo $_POST['customerList']; input_submit('go', 'go'); //return $qAllCustomers; } ?> </body> </html> I have three small tables and I'm looking for a clean, light, framework CRUD generator that I can use. Are there any that are small and light that dont require a full blown install like Symphony or phpObject Generator etc... Jared Hi all, iv benn search for a long time now for a sample on how to create MYSQL based data grid that have some CRUD functionality.. i am using dreamwever and the only thing i can get out of it is using the spray data set that gives me a table with sort abilities but i am looking for something more.. is there a PHP or JS sample of displying the data of MYSQL database that can can do CRUD and search abilities ? thank.. This topic has been moved to Beta Test Your Stuff!. http://www.phpfreaks.com/forums/index.php?topic=307377.0 Hey sorry that I am asking this question, though I have gotten around to learn connecting to a database and also do the retrieve, yet I am not necessarily getting to learn doing INSERT, UPDATE and DELETE the proper way.
The tutorials available are often not best, I have found a good book ("Object Oriented Programming in PHP5") which teaches SELECT, yet not necessarily INSERT, UPDATE and DELETE.
I am really wondering how does one get to learn CRUD with PHP OOP, how did you people learn this? How can I learn INSERT, UPDATE and DELETE as well with PHP OOP? I feel like paying for this on Elance or Fiverr. I am not sure how else to learn this by now, I have tried quite a bit, I have looked at scripts and tutorials and books. And it has just gotten as far as connecting to the database and doing the "fetching" ("SELECT", or also "retrieve"). Too bad that what is available is not necessarily best. Otherwise I would say one could understand the principle quickly and also pick up on a programming language quickly. Please bear with me, I would appreciate suggestions. Hi, I am creating my first OOP MVC content management system. I created a CRUD where on the Tag view page, you click edit and it takes you to the Tag edit page. But I want to improve the user experience, so when a user clicks edit, a modal window displays allowing editing of Tag, upon clicking save, modal window closes and AJAX updates Tag view page without refresh. You can see my Tag view.html here which is using Twig template system: {% extends "backendbase.html" %} {% block title %}Manage Tags{% endblock %} {% block body %} <h1 class="ui header">View Tags</h1> {% if tags.errors is not empty %} <div class="ui error message"> <p>Errors:</p> {% for error in tags.errors %} <div>{{ error }}</div> {% endfor %} </div> {% endif %} <table class="ui striped table"> <thead> <tr> <th>Id</th> <th>Tag</th> <th>Directory</th> <th>Synonyms</th> <th>Edit</th> <th>Test</th> <th>Delete</th> </tr> </thead> <tbody> {% for tag in tags %} <tr> <td>{{ tag.id }}</td> <td>{{ tag.tag }}</td> <td>{{ tag.tag_dir }}</td> <td>{{ tag.synonyms }}</td> <td><a class="edit" onclick="return false;" href="../edit/?edit={{ tag.id }}">Edit</a></td> <td><a href="../test/?test={{ tag.id }}">Test</a></td> <td><a href="../delete/?delete={{ tag.id }}">Delete</a></td> </tr> {% endfor %} </tbody> </table> <div class="ui modal"> <i class="close icon"></i> <div class="header"> Edit Tag </div> <div class="image content"> <!--<div class="ui medium image"></div>--> <div class="description"> <!-- <div class="ui header">We've auto-chosen a profile image for you.</div> <p>We've grabbed the following image from the <a href="https://www.gravatar.com" target="_blank">gravatar</a> image associated with your registered e-mail address.</p> <p>Is it okay to use this photo?</p> --> </div> </div> <div class="actions"> <div class="ui black deny button"> Cancel </div> <div class="ui positive right labeled icon button"> Save <i class="checkmark icon"></i> </div> </div> </div> <div class="ui divider"></div> <div class="ui pagination menu"> {% for page in pages %} <a href="{{ page.number|e }}" class="{{ page.isactive|e }}">{{ page.number|e }}</a> {% endfor %} </div> {% endblock %} If I add a form in the modal window with {{ tag.id }} and {{ tag.name }}, nothing displays obviously because it is not in the for in loop. My question is, what is the industry standard way of getting data into this modal window form? I could use a $_GET["id"] but then I am breaking MVC model by including code in template. Is the solution to use JavaScript to get ID from edit link, in the background get data from database then use JavaScript to create form in modal? Your help would be much appreciated! I've played around with CakePHP, then XCrud (a decent CRUD application) but I gave up on both of them, XCrud was great for everything up until it came to managing complicated relational database tables. Anyhow, I'm using wordpress a lot now cuz it lets me stop reinventing the wheel so much and although I was able to integrate XCrud into WordPress as a plugin, I think the best way to go is just transfer my database tables to WordPress tables and display them as custom post types. My time is really limited right now though, is there a plugin/set of plugins I can use to automate the process? To show you what I mean, heres the XCrud list display of one of the tables:
thats great because it automatically sets up the CRUD thing and lets you add and edit fields to the table, and doesn't heavily box you into their system but I have a table of plants, one for products, one for pharmacology, one for categories which are all related to each other, and some of them are structured in a tree/nested hierarchy structure so long story short, I need to do advanced searches based on these relations and handle these tree structured tables and CakePHP didn't work out, and XCrud has crappy documentation and isn't popular enough to find good info.
So how would you go about transfering this system to WordPress? I'm guessing I need to make custom post types for each table but what I don't yet know is how to transfer the DB tables to WordPress format, how to handle the relationships between each table and how to handle the hierarchical tree structures.
Hi
I just finished this tutorial('http://www.startutor...torial-part-3/)
and everything was working fine until I decided to add last names to the application.
I got everything working on all the other pages except the Update page.
This is my php code.
Hello I need a great help for my problem, I tried to insert multiple checkboxs for "$_POST active" in my CRUD and the values must be saved in the database but will be saved as "Array" everytime. foreach($_POST['active'] as $act){//query? } Here the PHP code <?php require_once "../lakota/config.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact'])) { if(isset($_POST["submit"])){ $activearr=$_POST["active"]; $newvalues= implode(",", $activearr); include_once "../lakota/checkboxClass.php"; $checkBoxClass=new checkboxClass(); echo $checkBoxClass->addtoDatabase($newvalues); } $sql = "INSERT INTO lakotabgs (faction, stations, active, pending, influence, id_fact) VALUES (?,?,?,?,?,?)"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("ssssss", $_POST['faction'], $_POST['stations'], $_POST["active"], $_POST['pending'], $_POST['influence'], $_POST['id_fact']); if ($stmt->execute()) { header("location: ../lakota/index.php"); exit(); } else { echo "Error! Try again later."; } $stmt->close(); } } $link->close(); } ?> HTML code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add new info</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> </head> <body> <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post"> <label><b>Active States</b></label> <input name="active[]" class="form-control" id="example1" type="checkbox" value="None" /> <label for="example1">None</label> <input name="active[]" class="form-control" id="example2" type="checkbox" value="Everybody" /> <label for="example2">Everybody</label> <input name="active[]" class="form-control" id="example3" type="checkbox" value="Unknown" /> <label for="example3">Unknown</label> <input type="submit" id="submit" name="submit" class="btn btn-primary" value="Add new info"> <a href="../lakota/index.php" class="btn btn-default">Back</a> </form> </body> </html> Edited November 14, 2020 by AccuCORE Hello All,
I've encountered one more problem (with the first WebApp I'm building), and I have no idea how to fix it. I've tried something, but it doesn't seem to work, so I'd appreciate some help in getting it fixed.
Here's what's happening:
So after I perform an operation (let's say "ADDing a record")...the records gets added correctly, but then, if/when I press [F5] in my browser window (or click on the Refresh/Reload icon), the same input details are being used and a second identical record is being added. I believe the same thing happens for some (or perhaps all) of the other CRUD operations.
What do I need to do to disable that behavior?
The only thing I could think of is to set the $functionSelected variable to blank ("") - which I've done towards the bottom of my code (shown below) - but that doesn't seem to be doing anything...the problem persists.
if(isset($_POST['action'])) { $functionSelected = $_POST["action"]; } if(isset($functionSelected)){ switch($functionSelected){ case "insert": $initialize_flag = "N"; // Store POST(ed) user-entered values into memory variables $store_name = $_POST['store_name']; $item_description = $_POST['item_description']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; $price = $_POST['price']; $flyer_page = $_POST['flyer_page']; $limited_time_sale = $_POST['limited_time_sale']; $flyer_date_start = $_POST['flyer_date_start']; $nos_to_purchase = $_POST['nos_to_purchase']; // Setup customized query $sql = "INSERT INTO shoplist (store_name, item_description, qty_pkg, pkg_of, price, flyer_page, limited_time_sale, flyer_date_start, nos_to_purchase, shopper1_buy_flag, shopper2_buy_flag, purchased_flag, purchase_later_flag) VALUES (:store_name, :item_description, :qty_pkg, :pkg_of, :price, :flyer_page, :limited_time_sale, :flyer_date_start, :nos_to_purchase, :shopper1_buy_flag, :shopper2_buy_flag, :purchased_flag, :purchase_later_flag)"; try { $statement = $conn->prepare($sql); $statement->bindParam(':store_name', $store_name); $statement->bindParam(':item_description', $item_description); $statement->bindParam(':qty_pkg', $qty_pkg); $statement->bindParam(':pkg_of', $pkg_of); $statement->bindParam(':price', $price); $statement->bindParam(':flyer_page', $flyer_page); $statement->bindParam(':limited_time_sale', $limited_time_sale); $statement->bindParam(':flyer_date_start', $flyer_date_start); $statement->bindParam(':nos_to_purchase', $nos_to_purchase); $statement->bindParam(':shopper1_buy_flag', $initialize_flag); $statement->bindParam(':shopper2_buy_flag', $initialize_flag); $statement->bindParam(':purchased_flag', $initialize_flag); $statement->bindParam(':purchase_later_flag', $initialize_flag); // Execute the query $statement->execute(); $statement->closeCursor(); $functionSelected = ""; // WILL THIS STATEMENT NOT SERVE TO INITIALIZE/RESET THE OPERATION??? break; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; } case "update-delete": ... ... ...Thanks. Something bothers me: I am writing a PHP code to implement "step by step" form. In order to do that, I copied a method which looks like: Program name: doit.php : if (!isset($_SESSION['para_stage'])) { ... first time to the code .... initialize variables ...display first form which calls doit.php when submit.....} else {already been to this code, variables are initialized, do what you have to do and recall doit.php ....} It works fine, but: isn't there a problem with calling the same program again and again from itself? isn;t it like a recursive, which means the stack will be used until overflow? Hello,
Here is my code:
<?php require 'vendor/autoload.php'; $client = new Elasticsearch/Client(); $root = realpath('~/elkdata/for_elk_test_2014_11_24/Agencies'); $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); $paths = array($root); foreach ($iter as $path => $dir) { if ($dir -> isDir()) { $paths[] = $path; } } //Create the index and mappings $mapping['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code $mapping['body'] = array ( 'mappings' => array ( 'documents' => array ( '_source' => array ( 'enabled' => true ), 'properties' => array( 'doc_name' => array( 'type' => 'string', 'analyzer' => 'standard' ), 'description' => array( 'type' => 'string' ) ) ) ) ); $client ->indices()->create($mapping) //Now index the documents for ($i = 0; $i <= count($paths); $i++) { $params ['body'][] = array( 'index' => array( 'type' => 'documents' 'body' => array( 'foo' => 'bar' //Document body goes here ) ) ); //Every 1000 documents stop and send the bulk request. if($1 % 1000) { $responses = $client->bulk($params); // erase the old bulk request $params = array(); // unset the bulk response when you are done to save memory unset($responses); } } ?>I am looking to index a large amount of documents using elastic search and php. I have a very complex directory filled with other directories that i need to index into an array. I wanted to see if my code looked right, and if not what am I doing wrong? Thanks, Austin Harmon I'm really fond of your coding and need some help too I'm also trying to make a tree and save it in an xml file such that parent_id of one node is inserted in as pages key to the father node.By running this query $sql = "Select * from category order by parent_id ASC"; I'm getting the following result. Array ( => Array ( [category_id] => 2 [parent_id] => 0 [category_name] => Clothes ) [1] => Array ( [category_id] => 5 [parent_id] => 1 [category_name] => T-shirts ) [2] => Array ( [category_id] => 6 [parent_id] => 1 [category_name] => Cotton-Shirts ) [3] => Array ( [category_id] => 1 [parent_id] => 2 [category_name] => Upper ) [4] => Array ( [category_id] => 4 [parent_id] => 2 [category_name] => Lower ) [5] => Array ( [category_id] => 3 [parent_id] => 4 [category_name] => Pants ) ) My code is as follows but not executing correctly function searchTree($arr,$node,$i){ if(!in_array($node['parent_id'],$arr[$i])) { $stmt = '<pages_'.$i.'>'; $stmt .=$node; $stmt .='</pages_'.$i.'>'; return $stmt;} else{ //print_r($returnTree); print_r ($arr[$i]);//['category_id']; $returnTree = ($arr[$i]['category_id']==$node['parent_id'])? searchTree($arr,$node,$i++): searchTree($arr,'',$i++); } } $i=0; foreach($links as $link){ $myArr = searchTree($links,$link,$i);} The result should be as follows: <page_1> <label>Clothes</label> <uri>#</uri> <pages> <page_1_1> <label>Upper</label> <uri>#</uri> <pages> <label>T-Shirt</label> <uri>#</uri> <page_1_1> <page_1_1_1> <label>Short Sleaves</label> <uri>#</uri> </page_1_1_1> <page_1_1_2><label>Long Sleaves</label><uri>#</uri> </page_1_1_2></page_1_1></page_1> <page_1_2> <label>Lower</label> <uri>#</uri> <pages>....</page_1_2> Hopefully you can unsderstand this problem. Please help me. Hello! Maybe I'm a bit ashamed to question some little kind of thing, but I tested 3 hours and couldn't let this function. It's like the most easiest possible recursiv function...: Code: [Select] function recursiv($s){ $s.="b"; if(strlen($s)>30){return $s;} //else return 0; else recursiv($s); } echo recursiv("h"); The result is a blank page... Thanks a lot for your help !! Code: [Select] public function getBonusChildren($userID) { if($userID != NULL) { $sql = 'SELECT COUNT(*) AS count, userID FROM jos_backoffice_users WHERE parentID= ' . $userID . ';'; $stmt = conn::getInstance()->prepare($sql); $stmt->execute(); $obj = $stmt->fetchAll(PDO::FETCH_ASSOC); if(is_object($obj)) { $obj->count += $this->getBonusChildren($obj->userID); } } return $obj->count; } I get no error. It just always return null. How can I get this done? If i have a list of categories like: 1. Billboards and advertisement section 1(a)City Clock 1(a)(i)Application fee (has columns for approved price and proposed price) 1(a)(ii)Advertisement Per year (has columns for approved price and proposed price) 1(b)Billboards 1(b)(i)Application fee for construction (has columns for approved price and proposed price) 1(b)(ii)Charge per year without advertisement (has columns for approved price and proposed price) 1(c)Something here..... 1(c)(i) something here...(has columns for approved price and proposed price) 1(c)(ii)something here...(has columns for approved price and proposed price) 1(c)(iii) something here... (has columns for approved price and proposed price) e.t.c THEN SOME CATEGORIES LOOK LIKE:category 2 2. Category name 2(a)something here..(has columns for approved price and proposed price) 2(b)something here.. 2(b)(i)something here..(has columns for approved price and proposed price) 2(b)(ii)something here..(has columns for approved price and proposed price) NOW: i have categories without sub categories and others with sub-sub categories , a main category doesn't does have a column for prices ( or lets just say other columns) , a sub category WITHOUT its sub category will have columns for prices, if a sub category has its sub category, then its subcategory should have columns for prices (this is where my problem is - how do i handle such a situation in php Mysql?? ) i have the below script but it doesn't work it just refreshes the page anyone know what is wrong Code: [Select] <?php $path = "../../gallery/gallery_files/gallery/"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { $dirname = $path; //Recursive Delete Function function DELETE_RECURSIVE_DIRS($dirname) { // recursive function to delete // all subdirectories and contents: if(is_dir($dirname))$dir_handle=opendir($dirname); while($file=readdir($dir_handle)) { if($file!="." && $file!="..") { if(!is_dir($dirname."/".$file))unlink ($dirname."/".$file); else DELETE_RECURSIVE_DIRS($dirname."/".$file); } } closedir($dir_handle); rmdir($dirname); return true; } } } ?> |