Delphi For PHP Forums    


Go Back   Delphi-PHP Forums > Programming > PHP - Code Snippets
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

PHP - Code Snippets Functional Code Snippets that other people may find useful. Post them here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11th September 2009, 18:11
D4PHP Newbie
 
Join Date: Sep 2009
Posts: 7
del@gainco.com is on a distinguished road
Default Dynamic Menu from MySQL table

I found a tutorial online creating a dynamic menu from a mysql table. I created the table and inserted the data then created the functions on a form to create the menul. when I run the form I get the following error:

"Fatal error: Call to undefined function wp_dyn_menu() in C:\Documents and Settings\del\My Documents\Delphi for PHP Projects\WebPromotions\wp_header.php on line 45"

Below is the code from the form, anyoone haave any ideas?


<?php
require_once("vcl/vcl.inc.php");
//Includes
require_once("wp_data_module.php");
use_unit("dbctrls.inc.php");
use_unit("menus.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class wp_header_form extends Page
{
public $Label1 = null;
public $DBRepeater1 = null;
public $Panel2 = null;
public $HeaaderImage = null;
public $Panel1 = null;
public $MenuArray = array("id","label","link_url","parent_id");

function wp_header_formBeforeShow($sender, $params)
{
$dynmenuQuery = GetDBModule()->wp_dyn_menu_sql;
$dynmenuQuery->Active = true;
$str = '';
for($dynmenuQuery->First(); !$dynmenuQuery->EOF; $dynmenuQuery->Next())
{
$MenuArray->id = $dynmenuQuery->id;
$MenuArray->label = $dynmenuQuery->label;
$MenuArray->link_url = $dynmenuQuery->link_url;
$MenuArray->parent_id = $dynmenuQuery->parent_id;
if ($MenuArray->parent_id == 0)
{
$parent_menu[$MenuArray->id]['label'] = $MenuArray->label;
$parent_menu[$MenuArray->id]['link'] = $MenuArray->link_url;
} else
{
$sub_menu[$MenuArray->id]['parent'] = $MenuArray->parent_id;
$sub_menu[$MenuArray->id]['label'] = $MenuArray->label;
$sub_menu[$MenuArray->id]['link'] = $MenuArray->link_url;
$parent_menu[$MenuArray->parent_id]['count']++;
}
}
echo wp_dyn_menu($parent_menu, $sub_menu, "menu", "nav", "subnav");
}

function rebuild_link($link, $parent_var, $parent_val)
{
$link_parts = explode("?", $link);
$base_var = "?".$parent_var."=".$parent_val;
if (!empty($link_parts[1]))
{
$link_parts[1] = str_replace("&amp;", "##", $link_parts[1]);
$parts = explode("##", $link_parts[1]);
$newParts = array();
foreach ($parts as $val)
{
$val_parts = explode("=", $val);
if ($val_parts[0] != $parent_var)
{
array_push($newParts, $val);
}
}
if (count($newParts) != 0)
{
$qs = "&amp;".implode("&amp;", $newParts);
}
return $link_parts[0].$base_var.$qs;
} else
{
return $link_parts[0].$base_var;
}
}

function wp_dyn_menu($parent_array, $sub_array, $qs_val = "menu", $main_id = "nav", $sub_id = "subnav", $extra_style = "foldout")
{
$menu = "<ul id=\"".$main_id."\">\n";
foreach ($parent_array as $pkey => $pval)
{
if (!empty($pval['count']))
{
$menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li>\n";
} else
{
$menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li>\n";
}
if (!empty($_REQUEST[$qs_val]))
{
$menu .= "<ul id=\"".$sub_id."\">\n";
foreach ($sub_array as $sval)
{
if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent'])
{
$menu .= "<li><a href=\"".rebuild_link($sval['link'], $qs_val, $sval['parent'])."\">".$sval['label']."</a></li>\n";
}
}
$menu .= "</ul>\n";
}
}
$menu .= "</ul>\n";
return $menu;
}

function Label1BeforeShow($sender, $params)
{
$sender->link = GetDBModule()->wp_main_menu->wp_menu_target;
}
function HeaaderImageBeforeShow($sender, $params)
{
$sender->ImageSource = GetDBModule()->wp_header_table->wp_header_image;
}

}

global $application;

global $wp_header_form;

//Creates the form
$wp_header_form=new wp_header_form($application);

//Read from resource file
$wp_header_form->loadResource(__FILE__);

//Shows the form
$wp_header_form->show();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11th September 2009, 23:49
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,480
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

Try
PHP Code:
echo $this->wp_dyn_menu($par 
If that doesn't work put your wp_dyn_menu function up above the class declaration.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12th September 2009, 00:53
D4PHP Newbie
 
Join Date: Sep 2009
Posts: 7
del@gainco.com is on a distinguished road
Default

Thanks for the responce, I tried both and now am getting: "Fatal error: Call to a member function wp_dyn_menu() on a non-object in C:\Documents and Settings\del\My Documents\Delphi for PHP Projects\WebPromotions\wp_header.php on line 101"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12th September 2009, 01:06
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,480
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

non-object means you don't want the $this->
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12th September 2009, 01:17
D4PHP Newbie
 
Join Date: Sep 2009
Posts: 7
del@gainco.com is on a distinguished road
Default

Thanks, with the two functions above the class decliration and no $this-> it does work but I do not have the sub menus. I will have to go back and check my data table and follow everything all the way through. Thanks, a lot for the help I am obviously new to D4PHP and PHP. I really apreciate the help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 04:53.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use