Re: My first XML!
| From: | olinux | Date: | Wed, 27 Nov 2002 08:01:18 +0000 |
| Subject: | Re: My first XML! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126245@lists.php.net to get a copy of this message | ||
Here's a start for you
<?
/* Connect to database */
$sql = "SELECT * FROM categories ORDER BY
parent_id,cat_id ASC";
$result = @mysql_query($sql) or die("Couldn't select
categories.");
$menu = array();
while ($row = mysql_fetch_array($result)) {
$id = $row['cat_id'];
$category = $row['category'];
$pid = $row['parent_id'];
$menu[$pid][$id] = $category;
}
function show_cats ($parent="", $indent="") {
global $menu;
foreach($menu as $key1 => $value1) {
if ($key1 == $parent) {// if it's a top category
print it
foreach ($value1 as $key2 => $value2) {
$catname = $value2; // $value2 same as
$value1[$key2]
$catID = $key2;
echo str_repeat(" ", $indent);
echo "<a
href=\"search/show_results.php?catID=$catID\">$catname</a><br>";
show_cats($catID, $indent+1);
}
}
}
} // end show_cats function
show_cats();
?>
--- Boris Kolev <boris@magicbg.com> wrote:
> Hello php-general,
>
> Hi.
> I want to know how i can export tree structure
> from Mysql table to
> XML
> mysql table structure is:
> ID - Group Unique Id
> P_ID - Parent Id
> Name - Name of group
>
> I want to make XML whit tree structure. Can some
> body help me!
>
>
> --
> Best regards,
> Boris
> mailto:boris@magicbg.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com