Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,427 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,886 people online right now. Registration is fast and FREE... Join Now!




Using template to generate a dynamic dropdown menu

 
Reply to this topicStart new topic

Using template to generate a dynamic dropdown menu

thiago.de.lima
8 Jan, 2008 - 12:19 PM
Post #1

New D.I.C Head
*

Joined: 8 Jan, 2008
Posts: 4

Hello there,

I've got this situation:

First

I've got a index.tpl who have a table contain 1 line merging two columns and two columns inserted independently. In the line I've put a header.tpl, at the first column I've put a login.tpl, and at the last column the register.tpl.

Second

I've got some dropdown menus into the register.tpl who needs to be filled with values from database.

So,

I wrote various scripts named select_role.php, select_jobpos.php, etc.. to generate the dynamic dropdown and substitute there into the register.tpl, so after that the index.php do the same but he substitute the commented block into the index.tpl

I am looking for someway to substitute a dynamic dropdown into the register.tpl without need to wrote a auxiliary script todo that for me. Anyone knows anything about how to do this?

My codes are below:

For index.php

CODE

<?
include_once './classes/template.class.php';
include_once './classes/imysql.class.inc';

$sql = new MySQL();
$sql->myConnect();

//create a new TemplatePower object using a file
$tpl = new TemplatePower( "./templates/index.tpl" );


//Define the header block
$tpl->assignInclude( "header", "./templates/header.tpl" );

//Define login blocks
$tpl->assignInclude( "login", "./templates/login.tpl" );

//Define registration blocks
$tpl->assignInclude( "register", "./templates/register.tpl" );

$tpl->prepare();

$tpl->printToScreen();

?>


For index.tpl

CODE

<html>
<head>
<title>Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="100%%" border="0">
  <tr>
    <td colspan="2">
        <!-- INCLUDE BLOCK : header -->
    </td>
  </tr>
  <tr>
    <td>
        <!-- INCLUDE BLOCK : login -->
    </td>
    <td>
    <!-- INCLUDE BLOCK : register -->
    </td>
  </tr>
</table>
</body>
</html>


for register.tpl
CODE

<style media="screen" type="text/css">
#op2{visibility:hidden;}
#op3{visibility:hidden;}
</style>
<!-- To create the visability or not of the Manager and Team Leader' fields -->
<script language="javascript">
function Changeoption(v)
{
    if (v.value == 0) {
        document.getElementById('op2').style.visibility='hidden';
        document.getElementById('op3').style.visibility='hidden';
    }
    if (v.value == 1){
        document.getElementById('op2').style.visibility='hidden';
        document.getElementById('op3').style.visibility='hidden';
    }
    if (v.value == 2){
        document.getElementById('op2').style.visibility='hidden';
        document.getElementById('op3').style.visibility='hidden';
    }
    if (v.value == 3){
        document.getElementById('op3').style.visibility='hidden';
        document.getElementById('op2').style.visibility='visible';
    }
    if (v.value == 4){
        document.getElementById('op2').style.visibility='visible';
        document.getElementById('op3').style.visibility='visible';
    }
    
}
</script>
    <form name="registered" method="post" action="register.php">
      <table width="50%" border="0" align="center">
        <tr>
            <td class='style'><div align='right'>ROLE</div>
                        </td>
                        <td colspan='2'>
                       <!-- INCLUDESCRIPT BLOCK : ./select_role.php -->
                        </td>
                   </tr>
                   <div align="right">
                    <input type="submit" name="Submit2" value="Ok">
                  </div>
                  </table>
              </form>


For select_role.php

CODE

<?php
    require_once './classes/imysql.class.inc';
    require_once './classes/template.class.php';
    
    //Populate the select box with their needs

    $sql = new MySQL();
    $sql->myConnect();
    $category = $sql->myExe("SELECT * FROM role");
    print "<select name='Role_Id_FK' id='Role_Id_FK'>";
    print "<option value='default'>- Choose -</option>>";
    while($line = $sql->myFetcharray($category)) {
          print "<option value='".$line['Role_Id_PK']."'>".$line['Role_Name']."</option>";
      }
    print "</select>";
?>


I will not write the others.

Anyone have any idea?

I am using template power class 3.0


User is offlineProfile CardPM
+Quote Post

ap0c0lyps3
RE: Using Template To Generate A Dynamic Dropdown Menu
8 Jan, 2008 - 01:16 PM
Post #2

D.I.C Head
Group Icon

Joined: 19 Jun, 2007
Posts: 79


Dream Kudos: 25
My Contributions
The fact that you are using Drop down menus obviously means that you are using JavaScript. What I do is use a jQuery plug-in. With this you can just create an unordered list and it will automatically create the menu for you.
User is offlineProfile CardPM
+Quote Post

thiago.de.lima
RE: Using Template To Generate A Dynamic Dropdown Menu
9 Jan, 2008 - 05:17 AM
Post #3

New D.I.C Head
*

Joined: 8 Jan, 2008
Posts: 4

QUOTE(ap0c0lyps3 @ 8 Jan, 2008 - 02:16 PM) *

The fact that you are using Drop down menus obviously means that you are using JavaScript. What I do is use a jQuery plug-in. With this you can just create an unordered list and it will automatically create the menu for you.


Ok, I've got

But, How does you populate the dropdown menu with sql data?

This plug-in do this task to you?

User is offlineProfile CardPM
+Quote Post

ap0c0lyps3
RE: Using Template To Generate A Dynamic Dropdown Menu
9 Jan, 2008 - 09:05 AM
Post #4

D.I.C Head
Group Icon

Joined: 19 Jun, 2007
Posts: 79


Dream Kudos: 25
My Contributions
Ok the plugin I told you about (http://jqueryplugins.com/plugins/view/59/) creates drop down menus from unordered lists. So all you have to do is create a php script that can generate that list. Here is a simple example

CODE
<?php
$menu = array( //Put your own array thing or your own menu system eg a sql system
'home' => array('exit', 'other stuff'),
'file' => array('new window'),
);
echo "<ul class='jdmenu jdmenu_slate'>";
foreach($menu as $name as $value) {
echo "<li>".$name."<ul>";
foreach($value as $menu) {
  echo "<li>".$menu."</li>";
}
echo "</ul></li>"
}
echo "</ul>";

That should create a dynamic menu from the array. As long as you include the jquery and jdsharp files in your html file.

This post has been edited by ap0c0lyps3: 9 Jan, 2008 - 09:06 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:48AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month