Current location: Hot Scripts Forums » Advertising Forums » Job Offers & Assistance » [PAID] Dynamic Drop Down Menu


[PAID] Dynamic Drop Down Menu

Reply
  #1 (permalink)  
Old 05-08-06, 12:16 PM
Coconut Coconut is offline
New Member
 
Join Date: May 2006
Location: Aggie Land, Texas
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[PAID] Dynamic Drop Down Menu

I needed a PHP/MySQL dynamic drop down and I have hired a coder who have done pretty much 1/2 ~ 3/4 of the job. Right now, through the admin page, I could add items to the database and the drop down, and can associate the options of the of the 4 drop downs with its precedent drop down option.

Now, I need a table as of this:

http://hammoudy.com/Junk/PCKengine.gif

in the admin page, where I could input datas that will be linked to each vehicle according to its year/make/model and engine and an option where I could add more rows. In the user page, when the user selects the year/make/model/engine from the drop down menus, it will display the same table as in the admin page.

This is the installation file, which includes the database structure:
PHP Code:

<?

//including global constants, username, password, host and dbname
include("config.php");


//connecting to database, else printing error
$conn mysql_connect($host$user$password);

//checking database exists
$db_list mysql_list_dbs($conn);

$i 0;
$cnt mysql_num_rows($db_list);
$dbexists false;
while (
$i $cnt) {
    if(
mysql_db_name($db_list$i)==$dbname) {
          
$dbexists true;
          break;
     }
    
$i++;
}

//creating the database schema $dbname
if(!$dbexists) {
     
$query_create_db "CREATE DATABASE $dbname";
     
$res0 mysql_query($query_create_db) or die(mysql_error());
}

//selecting db
mysql_select_db($dbname);

//query for dropping table node
$query_drop_node "DROP TABLE IF EXISTS node";
//query for creating node table
$query_create_node "CREATE TABLE `$dbname`.`node` "
               
."(`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,`name` VARCHAR(100) NOT NULL DEFAULT '', "
               
."PRIMARY KEY(`id`))";

//query for dropping table relation
$query_drop_relation "DROP TABLE IF EXISTS relation";
//query for creating relation table
$query_create_relation "CREATE TABLE `$dbname`.`relation` ("
               
."`parent_id` INTEGER UNSIGNED NOT NULL DEFAULT 0,"
               
."`child_id` INTEGER UNSIGNED NOT NULL DEFAULT 0,"
               
." PRIMARY KEY(`parent_id`, `child_id`))";

//query for inserting root node
$query_ins_node "insert into node(id, name) values(1, 'root')";

$res1a mysql_query($query_drop_node);
$res1b mysql_query($query_create_node);
$res2a mysql_query($query_drop_relation);
$res2b mysql_query($query_create_relation);
$res3 mysql_query($query_ins_node) or die(mysql_error());
?>
<html>
<body>
database installed successfully
</body>
</html>
and this is the admin page where I can add items to the database and do the linking between the option in each drop menu.

PHP Code:

<html>

<head>
     <title>Admin Page</title>
</head>
<body>
<?
include("config.php");
$conn mysql_connect($host$user$password);
mysql_select_db($dbname);
if(isset(
$_POST['submit'])) {
     if(isset(
$_POST['p']) && $_POST['p']!=0) {
          
$p $_POST['p'];
          
$name $_POST['name'];
          
$ins_query "insert into node(name) values('$name')";
          
$res0 mysql_query($ins_query) or die(mysql_error());
          
$id mysql_insert_id($conn);
          
$rel_query "insert into relation(parent_id, child_id) values('$p', '$id')";
          
$res1 mysql_query($rel_query) or die(mysql_error());
          
$msg "Value successfully inserted";
     } else {
          
$error "Parent ID not passed";
     }
}

$vvar = array();
$vvar[0] = "";
for(
$i 1;$i <= $maxSub;$i++) {
     
$vname "v" $i;
     if (isset(
$_GET[$vname])) {
          
$vvar[$i] = $_GET[$vname];
     } else {
          break;
     }
}
if(isset(
$msg)) {
     echo 
$msg;
}
?>

<script type="text/javascript">
<?
$jsv 
= array();
$jsv[0] = "?";
for(
$i 1;$i <= $maxSub;$i++) {
     
$jsv[$i] = $jsv[$i-1] . $vvar[$i-1] . "&v" $i "=";

     
?>
               function select<?="v" $i?>(v1) {
                    window.location = "<?=$jsv[$i]?>" + v1;
               }
<?
}

?>
</script>
<table border="0">
<?
$parent 
1;
$str1 "";
for(
$i 1;$i <= $maxSub;$i++) {
     
$next 0;
     if (
$parent != 0) {
          
$q1 "select child_id from relation where parent_id='$parent' order by child_id";
          
$r1 mysql_query($q1) or die(mysql_error());
          if (isset(
$vvar[$i])) {
               
$sel $vvar[$i];
               
$next $sel;
          } else {
               
$sel 0;
          }
          
$str1 .= "<option value=\"0\">Select Option</option>";
          while (
$arr1 mysql_fetch_assoc($r1)) {
               
$id1 $arr1['child_id'];
               
$q2 "select name from node where id = '$id1'";
               
$r2 mysql_query($q2) or die(mysql_error());
               
$arr2 mysql_fetch_assoc($r2);
               
$n2 $arr2['name'];
               if (
$id1 == $sel) {
                    
$str1 .= "<option value=\"$id1\" selected=\"selected\">$n2</option>\n";
               } else {
                    
$str1 .= "<option value=\"$id1\">$n2</option>\n";
               }
          }
     }

     
?>
     <tr>
          <td>
          <?
     
if (strcmp($str1,"" ) == 0) {
          
?>
                         <select name="choice">
                         <option value="0">Select Option</option>
          <?
     
} else {
          
?>
                         <select name="choice" onChange="select<?="v" $i?>(this.options[this.selectedIndex].value)">
          <?=$str1?>
          </select>
          <?
     
}
          
?>
          </td>
          <td>
          <form method="post" action="admin.php?<?=$_ENV['QUERY_STRING']?>">
               <input type="text" name="name">
               <input type="hidden" name="p" value="<?=(($i==1)?1:$parent)?>">
               <input type="submit" name="submit" value="submit">
          </form>
          </td>
     </tr>
<?
     $parent 
$next;
     
$str1 "";
}

?>
</table>
</body>
</html>
<?
if ($conn)
     
mysql_close($conn);

?>
and this is the user interface. As of now, once all fields are selected, nothing happens. I need a table with the exact structure and infos that were inputted in the admin page to show.

PHP Code:

<?

include("config.php");
$conn mysql_connect($host$user$password);
mysql_select_db($dbname);

?>
<html>
<head>
     <title>User Page</title>
</head>
<body>
<?
$vvar 
= array();
$vvar[0] = "";
for(
$i 1;$i <= $maxSub;$i++) {
     
$vname "v" $i;
     if (isset(
$_GET[$vname])) {
          
$vvar[$i] = $_GET[$vname];
     } else {
          break;
     }
}

?>

<script type="text/javascript">
<?
$jsv 
= array();
$jsv[0] = "?";
for(
$i 1;$i <= $maxSub;$i++) {
     
$jsv[$i] = $jsv[$i-1] . $vvar[$i-1] . "&v" $i "=";

     
?>
               function select<?="v" $i?>(v1) {
                    window.location = "<?=$jsv[$i]?>" + v1;
               }
<?
}

?>
</script>
<form action="index.php" method="GET">
<table border="0">
<?
$parent 
1;
$str1 "";
for(
$i 1;$i <= $maxSub;$i++) {
     
$next 0;
     if (
$parent != 0) {
          
$q1 "select child_id from relation where parent_id='$parent' order by child_id";
          
$r1 mysql_query($q1) or die(mysql_error());
          if (isset(
$vvar[$i])) {
               
$sel $vvar[$i];
               
$next $sel;
          } else {
               
$sel 0;
          }
          
$str1 .= "<option value=\"0\">Select Option</option>";
          while (
$arr1 mysql_fetch_assoc($r1)) {
               
$id1 $arr1['child_id'];
               
$q2 "select name from node where id = '$id1'";
               
$r2 mysql_query($q2) or die(mysql_error());
               
$arr2 mysql_fetch_assoc($r2);
               
$n2 $arr2['name'];
               if (
$id1 == $sel) {
                    
$str1 .= "<option value=\"$id1\" selected=\"selected\">$n2</option>\n";
               } else {
                    
$str1 .= "<option value=\"$id1\">$n2</option>\n";
               }
          }
     }

     
?>
     <tr>
          <td>
          <?
     
if (strcmp($str1,"" ) == 0) {
          
?>
                         <select name="choice">
                         <option value="0">Select Option</option>
          <?
     
} else {
          
?>
                         <select name="choice" onChange="select<?="v" $i?>(this.options[this.selectedIndex].value)">
          <?=$str1?>
          </select>
          <?
     
}
          
?>
          </td>
     </tr>
<?
     $parent 
$next;
     
$str1 "";
}

?>
</table>
</form>
</body>
</html>
<?
if ($conn)
     
mysql_close($conn);

?>
You could test drive the demo:

Admin: http://hammoudy.com/Partsrex/admin.php
User interface: http://hammoudy.com/Partsrex/index.php

The way it works is, you input the year in the first field in the admin page - say it's 1999. From the first drop down, you select 1999, which was just input, and add a value which is supposed to be the make of the vehicle in the second field and hit submit - say you input Honda. From the second drop down you select Honda, and enter a value, which is the model in the third field and hit submit ... Now, after you enter the last value for the 4th field which is the engine size, the table will have to show up (which I have taken a screenshot of) and I will have the ability to enter value for each field, which will be stored in the same table row of its associated vehicle (year/make/model/engine). The same table structure will be displayed when users select the year/make/model/engine of his vehicle in the user interface index.php page.


If you could do the required job, kindly PM me with a quote and the time frame you need to accomplish this task.
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic menu item creation for "Tigra" (DHTML) menu. HELP! qin1 PHP 0 02-10-06 08:38 AM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM
Creating a drop down menu ? ? ? Spreegem PHP 4 03-09-05 09:34 AM
Drop Down menu order peterc PHP 1 08-20-04 02:23 AM
drop down menu problem !!! nurqeen PHP 1 02-08-04 08:07 PM


All times are GMT -5. The time now is 12:42 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.