asawyer13
Posts: 46
|
| Posted: 12/26/2008, 4:13 PM |
|
I am trying to add a Tigra menu to my header page so it will be on each page of my website.
As part of doing this, I need to add the following code that will create the dynamic menu for me.
I can't seem to get it added without it giving me an error.
Right now, I am adding it to my html code, though I am open to suggestions.
This is the code:
<script language="JavaScript" src="menu_files/menu.js"></script>
<script language="JavaScript" src="menu_files/template.js"></script>
<link rel="stylesheet" href="menu_files/menu.css">
<script language="JavaScript">
<?php build_hierarchy_var('localhost', 'mysqluser', '', 'mydatabase', 'mytable', 'MENU_ITEMS0', 'id', 'parent_id', 'node_name', 'node_url');?> </script>
Of course, I replace mysqluser, mydatabase and mytable with proper values.
I include the build_hierarchy_var function in a functions directory like Feha suggested in another forum, but I know the error is being generated by that line.
I suspect it's a matter of syntax, though I don't know.
If someone can and is willing to help, I sure would appreciate it.
Alan
|
 |
 |
damian
Posts: 838
|
| Posted: 12/27/2008, 1:53 AM |
|
what is the error message?
can you post a link to the page?
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 5:28 AM |
|
It is not a production site yet, so I can't give you the url. I am testing locally.
The error I get in IE7 is
Line: 18
Char: 2
Error: Syntax error
Code: 0
URL: http://localhost/testdomain/address_list.php
which is the php file that has the header page included in it.
I don't get the error, if that one line in the header html file is not there.
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 5:31 AM |
|
The same code placed intoTigra's demo php file works fine (after I take out the 'php'.
So it's very possible if I knew where to put the code in my php code, I would be fine, however I am not sure where to put it.
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 5:52 AM |
|
Damian,
I saw a post in 2005 where you were talking about adding php code by using a Label.
I went ahead and tried that.
I added a label in my header page, and inserted my javascript code in the BeforeShow.
I now get an error when I execute my page that says:
Parse error: syntax error, unexpected '<' in V:\xampp\htdocs\testdomain\Header_events.php on line 15
Line 15 is the first line of my BeforeShow code, which is:
<script language="JavaScript" src="menu_files/menu.js"></script>
Not sure if I'm getting closer or farther from getting it to work, but any help would be appreciated.
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 6:26 AM |
|
I am making a little progress.
I moved the script language stuff to the header.html file.
I then just had the
build_hierarchy_var('localhost', 'mysqluser', '', 'mydatabase', 'mytable', 'MENU_ITEMS0', 'id', 'parent_id', 'node_name', 'node_url');?>
That threw an error that build_hierarchy_var wasn't found. I had 2 functions that I added via a method that feha had suggested in an earlier post, but I decided to just go ahead and include them in the BeforeShow code.
This didn't give me an error, but part of the first function uses some syntax that I'm not familiar with, to return a variable.
The function looks like this.
function build_hierarchy_var($sip, $un, $upw, $dbn, $tabname, $varname, $id_fn, $pid_fn, $c_fn, $l_fn)
{
$conn = mysql_connect($sip, $un, $upw);
if (!$conn)
{
echo 'Unable to connect to DB: ' . mysql_error(); return;
}
if (!mysql_select_db($dbn))
{
echo 'Unable to select mydb: ' . mysql_error(); return;
}
?>var <?=$varname?> = [<? build_hierarchy(0, 1, $tabname, $id_fn, $pid_fn, $c_fn, $l_fn); ?>];<? }
The line that has var and $varname is what I'm confused about. When I execute my page now, it shows the variable information on the page instead of returning it to the code that called it.
I know the ?> codes, etc, are causing the issues, but the code works on Tigra's demo, and I'm not sure exactly what to change.
I'm really close, but not quite there.
Help..
Alan
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 12/27/2008, 6:54 AM |
|
Hi
I am assuming you are generating this page in CCS.
If you are trying to put php code in the HTML using CodeCharge, it will not work.
PHP is server side code and if you take a look as to how CCS generates it's pages using the templates it is impossible for php code to execute since it is simply shipped to the browser and does not go thru the server.
The syntax errors I would suspect are javascript errors since java does not know about php code.
Does that help any
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 7:36 AM |
|
It helps me understand why I'm having a problem.
I would think there would be some way to make this work.
Can I create a Header.php page that's outside of CCS and have CCS just include it??
Basically my header would be a logo, and the Tigra menu.
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 7:40 AM |
|
The Horizontal JS Menu that's included in sample pack 2 works using the Tigra menu, but it's using a Directory Builder, and it's not as flexible as I need. The Tigra code that runs in the Tigra demo is very simple to load all the menus that I need to do.
The code in the html page on the Horizontal JS menu is:
<script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
<!-- BEGIN Directory menu -->
var MENU_ITEMS = [
<!-- BEGIN Category -->['{CategoryLink}', null, null ,
<!-- BEGIN Subcategory -->['{SubcategoryLink}','{Label1}']<!-- END Subcategory -->
<!-- BEGIN SubcategorySeparator -->,<!-- END SubcategorySeparator -->
<!-- BEGIN SubcategoriesTail --><!-- END SubcategoriesTail -->
],
<!-- END Category -->
<!-- BEGIN CategorySeparator --><!-- END CategorySeparator -->
<!-- BEGIN ColumnSeparator --><!-- END ColumnSeparator -->
<!-- BEGIN NoCategories --><!-- END NoCategories -->
];
<!-- END Directory menu -->
</script>
</head>
<body>
{Header}
<h1>An implementation of database-driven horizontal <a href="http://www.softcomplex.com/products/tigra_menu/" target="_new">Tigra menu</a> (JavaScript)</h1>
<p><a href="{Link1_Src}" id="Link1">View more information about this example</a></p>
<script language="JavaScript">
new menu (MENU_ITEMS, MENU_POS);
</script>
so could I replace the var MENU_ITEMS with part of the code that's in my Build_hierarchy_var??
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 7:48 AM |
|
I'm open to any suggestions to make this work.
If you have an idea of how it could work, I would be willing to pay something for it. I have spent probably 2 hours on it, and don't seem to be making much progress.
I don't really want to use the example pack 2 option, but I guess if I have to, I could do it.
Let me know what you think.
Alan
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 12/27/2008, 8:50 AM |
|
Hi Alan.
There could be several ways to do this.
1. Use $Tpl->setvar("MENU_ITEM",$YourMenuString); and set MENU_ITEM in {} curly braces in the javascript. this way you can create the stuff on the fly in PHP and stuff it in before the template goes out.
2. Include a page that does what you want in php and generates your javascript for you and by using the php buffer obstart() run the code then output it as a string.
3. create a php file that creates your javascript and make it the src= argument to a script tag in your html.
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 9:03 AM |
|
The main problem I will have if I use the example pack 2 method is that it doesn't allow the first level menu to be able to be clicked so I don't have a good way to create a HOME button, or any menu that doesn't have a second level.
I could use this method for now if that could be corrected.
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 9:04 AM |
|
John,
Just saw your reply. I will try to give it a shot.
Thanks,
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 11:27 AM |
|
I decided to try option 3. It seemed the most straigtforward.
I created a php file called TGmenu.php that when run via http://localhost/testdomain/TGmenu.php outputs my menu.
Now I added to my header.html file this code:
<script type="text/javascript" src="TGmenu.php"> </script>
Of course, I have a php file and not a javascript file, so I'm not sure if I didn't understand what you were saying, or if I just did it incorrectly.
Should this be correct?
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 1:19 PM |
|
John,
If you could explain option 1 a little bit more, I could also try it.
Alan
|
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/27/2008, 4:54 PM |
|
I used Option 2 and actually got it working.
Very cool.
Thanks for your help.
Alan
|
 |
 |
damian
Posts: 838
|
| Posted: 12/27/2008, 6:23 PM |
|
good work Alan, could you post your working solution?
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 12/28/2008, 6:39 AM |
|
Hi Alan
Glad you got it working.
Item 1 and 3 are similar. In both cases you would have your php code create the javascript.
In the case of Item 1. Your html would look like <script type="text/javascript">{MENU_ITEM}</script>
The php in the before show or before output event would be:
global $Tpl;
$Tpl->setvar("MENU_ITEM",$YourJavaScriptStringofCode);
This would not require an include since you would create the javascript in the file itself.
This would but your javascript into the label {MENU_ITEM}
In the case of item 3 your src="TGMenu.php" line would open a php file that also just creates the javascript code.
The php file would simply create the javascript code you want so your php file would looke like this
<?
php code to create your javascript string;
echo $YourJavascriptString;
exit;
All three methods will get the effect you are looking for.
I am glad option 2 worked for you.
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/28/2008, 6:57 AM |
|
Thanks,
One of the things I'm also wanting to do is create a countdown clock on my front page indicating when the site will be going live.
I wouldn't think option 2 will work for that, so I will also be trying to understand and implement option 1 and 3 so I really learn how this piece works.
Thanks again,
Alan
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 12/28/2008, 7:08 AM |
|
Cool
Actually option 1 is the most strait forward since it does not require an include or external file. You would create the javascript within the script that is running. That way you would have access to all the databases the page is using and do not have to duplicate that in anouther page.
The advantage of option 3 is your javascript source would be hidden and not visible in the html source. It can, however, actually be a CCS script so you could easily implement and CCS functions you might need. Just echo your javascript string and exit functions after you have the entire string built. Like may the before output or before show event. (If you build the stgring somewhere other than the event you echo it remember to make it global.)
Have fun
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
asawyer13
Posts: 46
|
| Posted: 12/29/2008, 6:39 PM |
|
John,
You were right about option 1 being the easiest.
I actually got my javascript countdown timer to work pretty well on my page. I will post the code if anyone's interested.
I haven't gone back yet and done the menu, but I'm sure I will give it a shot before this weekend.
Alan
|
 |
 |
|