PDA

View Full Version : Dynamic drop down menu using dreamweaver


kevy
06-26-2008, 07:40 PM
Hi. Here's my problem.

I have two tables. One is a main category table and the other is a subcategory table.

The main category table has the fields (catID and catName)

The Subcategory table has the fields (catId, SubId and SubName)

The two are related via the catId field..

I can't figure out how to dynamically load the second drop down menu from the choice made in the first drop down menu.. If anybody can point out whats wrong, it would be nice :) Thanks.



<?php require_once('Connections/antiques.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_antiques, $antiques);
$query_Recordset1 = "SELECT * FROM itemmastercategory";
$Recordset1 = mysql_query($query_Recordset1, $antiques) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_antiques, $antiques);
$query_Recordset2 = "SELECT * FROM itemmastercategory";
$Recordset2 = mysql_query($query_Recordset2, $antiques) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="select" id="select">
<option value="">Choose Antique Category</option>
<?php
do {
?>
<option value="<?php echo $row_Recordset1['CatId']?>"><?php echo $row_Recordset1['CatName']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label>
<label>
<select name="select2" id="select2">
<option value="">Choose Antique Sub Category</option>
<?php
do {
?><option value="<?php echo $row_Recordset2['SubId']?>"><?php echo $row_Recordset2['SubName']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</label>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>

lux
06-26-2008, 08:41 PM
Ok well that's dreamweaver code and its pants so your best off learning how to code php.

the videos in the tutorial section are the perfect place to begin.

once you've mastered the basics there is a video tutorial that uses a combination of php and ajax to accomplish your goal.

domedia
06-26-2008, 10:13 PM
I need to rename this forum from 'coders forum' to 'handcoders forum' :) It's not intuitive enough right now.

lux
06-26-2008, 10:18 PM
good point domedia

kevy, search the adobe dev centre and see if they have any tuts/tips for you if you want to carry on using the dreamweaver wizards

all the best

davidj
06-26-2008, 10:35 PM
notice i kept quiet!

im proud of myself

kevy
06-27-2008, 06:08 AM
Hi guys,

there's no doubt in my mind that if I learned how to code from scratch, i'd be better off in the long run. However, because of a limited amount of time and the small amount of coding I actually need done for my site, using dreamweaver is the logical move going forward.

I used dreamweaver developers tool box and now have working drop down menus.

The only thing I need now is a submit button that takes the information chosen in the drop down menu and displays all the fields associated with the dropdown menu fields chosen. Does that make sense? lol

Anybody got any ideas? Would I need a cgi script to do something like that?

lux
06-27-2008, 07:46 AM
you could always use php

davidj
06-27-2008, 07:49 AM
at the end of the day someone will have to write this for you

you are starting to find the limits of dreamweaver

2bz2p
06-27-2008, 03:03 PM
notice i kept quiet!

im proud of myself

I was waiting to see the reply :mrgreen:

domedia
06-27-2008, 04:06 PM
there's no doubt in my mind that if I learned how to code from scratch, i'd be better off in the long run. However, because of a limited amount of time and the small amount of coding I actually need done for my site, using dreamweaver is the logical move going forward. No problem kevy, many people go that route. Unfortunately this is the subforum for PHP handcoders, not people that use DW to write their code (the two seem to be incomatible ;) )

kevy
06-27-2008, 04:53 PM
Ok fair enough :)

How much would it cost for somebody to write up the rest of what's missing here? There isn't much really left..

On a seperate page, I would like the table items in the subtable with the same categoryID as the category chosen in the second drop down menu to be displayed..

Does that make sense?

My algorithm would be something like:

display * from itemsubcategory where catID = form.select2

where catID is the foreign key in my second table itemsubcategory and form.select2 is the second drop down menu...

What do you guys think? Who's up for a challenge?

kevy
06-27-2008, 05:58 PM
<?php echo $_POST['select2']; ?>


The code is sent from my form on the other page to this page.. This command displays what is sent from the select2 drop down..

How can I name this as a new variable? Anybody?

davidj
06-27-2008, 06:07 PM
i can help you learn PHP but cant help with this

sorry

kevy
06-27-2008, 06:18 PM
is there just too much added code with dreamweaver that it's too hard to sort it all out??

domedia
06-27-2008, 07:04 PM
DW makes it's own programming logic.. that's why I said a handcoder and DW's stuff are often incompatible, although I'm sure you can make this work with DW alone. Did you have a look at some of the tutorials and articles on adobe.com for using DW to write a php app?

kevy
06-27-2008, 07:17 PM
lol ya for like the past 36 hours.. I dunno this seems like a simple thing to do but I can't figure it out.

davidj
06-27-2008, 07:26 PM
if you would like to learn then i am available for one to one tuition

kevy
06-27-2008, 07:49 PM
I'm interested yes.. Whats the damage $$?

davidj
06-27-2008, 07:50 PM
i ask you to make a donation every couple of lessons

kevy
06-27-2008, 10:22 PM
not a problem, can you contact me on msn? kevstero@hotmail.com

davidj
06-28-2008, 01:06 AM
contact me throught the PM system

tell me what level you are at regarding html etc

kevy
06-28-2008, 02:23 AM
<?php echo $_POST['select2']; ?>

$query_Recordset1 = "SELECT * FROM itemsubcategory WHERE itemsubcategory.SubId = $_POST['select2']";


I get an error when i make itemsubcategory.subId = $_POST['select2']"

Any ideas why?

kevy
06-28-2008, 04:12 AM
nevermind :)