domka
asked on
Make menu tree with ajax, php and mysql
How create menu tree with ajax, php and mysql?is it possible, please help.thank you
ASKER
thank you.
how make such array tree from mysql and php with while loop?
$tree_data = array(
array(
url => "",
parent => "0",
name => "Home"),
array(
url => "",
parent => "Home",
name => "About"),
array(
url => "",
parent => "Home",
name => "Contact"),
array(
url => "",
parent => "0",
name => "Our Products"),
array(
url => "http://www.OpenCrypt.com/",
parent => "Our Products",
name => "OpenCrypt"),
array(
url => "http://www.OpenCrypt.com/features.php",
parent => "OpenCrypt",
name => "Features and Benefits"),
array(
url => "http://demo.OpenCrypt.com/",
parent => "OpenCrypt",
name => "Demonstration"),
array(
url => "http://www.OpenCrypt.com/",
parent => "Demonstration",
name => "Another Tier"),
array(
url => "http://www.OpenCrypt.com/",
parent => "Another Tier",
name => "And Another"),
array(
url => "http://www.OpenCrypt.com/",
parent => "And Another",
name => "And Another Tier"),
array(
url => "http://www.Locked-Area.com/",
parent => "Our Products",
name => "Locked Area"),
array(
url => "http://www.DirectoryPass.com/",
parent => "Our Products",
name => "DirectoryPass")
);
how make such array tree from mysql and php with while loop?
$tree_data = array(
array(
url => "",
parent => "0",
name => "Home"),
array(
url => "",
parent => "Home",
name => "About"),
array(
url => "",
parent => "Home",
name => "Contact"),
array(
url => "",
parent => "0",
name => "Our Products"),
array(
url => "http://www.OpenCrypt.com/",
parent => "Our Products",
name => "OpenCrypt"),
array(
url => "http://www.OpenCrypt.com/features.php",
parent => "OpenCrypt",
name => "Features and Benefits"),
array(
url => "http://demo.OpenCrypt.com/",
parent => "OpenCrypt",
name => "Demonstration"),
array(
url => "http://www.OpenCrypt.com/",
parent => "Demonstration",
name => "Another Tier"),
array(
url => "http://www.OpenCrypt.com/",
parent => "Another Tier",
name => "And Another"),
array(
url => "http://www.OpenCrypt.com/",
parent => "And Another",
name => "And Another Tier"),
array(
url => "http://www.Locked-Area.com/",
parent => "Our Products",
name => "Locked Area"),
array(
url => "http://www.DirectoryPass.com/",
parent => "Our Products",
name => "DirectoryPass")
);
It seems like you answered your own question. Although you don't have to use a while loop you will need some loop. In some cases PHP has a built in function to make arrays, etc from database results. Otherwise you would just manually make it.
Since you know how the info is in the DB you should know whether or not the results of an SQL search could just quickly be put in an array like that. If not then your "loop" will need even more script to manipulate or process the info.
Sorry I can't be specific. No details on the DB, fields, values, etc to be able to provide them. You are on the right track with the loop though.
For this main question did the page provide what you need to make a menu? Since DBs will be different and your values not like theirs you will need to adapt what they provided. I can try to help but would need the details. :) Let me know if you have a question or how that site fits what you asked here.
bol
Since you know how the info is in the DB you should know whether or not the results of an SQL search could just quickly be put in an array like that. If not then your "loop" will need even more script to manipulate or process the info.
Sorry I can't be specific. No details on the DB, fields, values, etc to be able to provide them. You are on the right track with the loop though.
For this main question did the page provide what you need to make a menu? Since DBs will be different and your values not like theirs you will need to adapt what they provided. I can try to help but would need the details. :) Let me know if you have a question or how that site fits what you asked here.
bol
ASKER
thank you for yours mind, bol
i need ajax tree menu, because offers dont like page reload, when i make tree menu by php variables.
so i need make array. i try, but i dont know how make such structure in loop
url => "",
parent => "0",
name => "Home"),
i need ajax tree menu, because offers dont like page reload, when i make tree menu by php variables.
so i need make array. i try, but i dont know how make such structure in loop
url => "",
parent => "0",
name => "Home"),
$SQL = "SELECT * FROM p_kategorijas WHERE pid=0 ORDER BY pavadinimas_lt ASC";
$RES = mysql_query($SQL) or die(mysql_error());
$array1[]=array();
$array2[]=array();
while($row = mysql_fetch_array($RES)){
$SQL1 = "SELECT * FROM p_kategorijas WHERE pid=$row[katID] ORDER BY pavadinimas_lt ASC";
$RES1 = mysql_query($SQL1) or die(mysql_error());
$num=mysql_num_rows($RES1);
if($num>0){
// $array1=(url "=>" "",
//parent "=>" "0",
// name => "$row[$pavadinimas]"),);
//echo"<div style='text-indent: 20px'>$row[$pavadinimas]</div>";
}else{
//$array1=(url => "",
//parent => "0",
//name => "$row[$pavadinimas]"));
//echo"$row[$pavadinimas]";
//echo"<div style='text-indent: 20px'><a href='prekes.php?katID=$row[katID]'>$row[$pavadinimas]</a></div>";
}
while ($row1 = mysql_fetch_array($RES1))
{
// $array2=(url => "",
//parent => "$row[$pavadinimas]",
//name => "$row1[$pavadinimas]"),);
//echo"<div style='text-indent: 25px'><a href='prekes.php?katID=$row1[katID]'> <li>$row1[$pavadinimas]</a></div>";
}
}
// $tree_data1=array($array1[$array2]);
What are the fields in the database? What is their order? I assume the data type is like varchar or some similar "string" type. Please confirm.
Thanks for the script. With some details about the DB I will look at it to see if I can help with the specifics. :)
bol
Thanks for the script. With some details about the DB I will look at it to see if I can help with the specifics. :)
bol
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One example is provided at http://www.opencrypt.com/blog.php?a=23 . Of course you could leave out the AJAX and MySQL but the example there depends on AJAX and can use a database.
Let me know if you have any questions or need more information.
b0lsc0tt