SELECT where bla bla
heb hier een dual dropdown formulier en dat werkt prima. Maar nu wil ik het id nummer van de gekozen selectie met een SELECT uit de db halen en met een hidden form field met GET doorsturen naar een volgende pagina.
Maar na heel veel trail & error.... krijg ik de where niet juist in de query
Kan iemand helpen?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?
// Database connection
$db_database = 'xxx';
$db_host = 'localhost';
$db_user = 'xxxxxx';
$db_pass = 'xxxx';
mysql_connect($db_host,$db_user,$db_pass) or die("Could not connect to MySQL (Main connection)");
mysql_select_db($db_database) or die("Could not connect to database (Main connection)");
function dual_linked_select(
$table, // Table to create linked selects from
$table_column_01, // Root category
$table_column_02, // Subcategory of the root category
$group_02_default_option_text // Default option text for the group 2 select
)
{
// Define globals
global $javascript;
global $group_01_options;
// Define variables
$javascript = null; // Hold
$group_01_options = null;//Hold
// Assembly of Javascript starts
$javascript .=<<<content
/* Linked Dropdown Selects Script Start */
function DefaultGroup2()
{
var x = document.getElementById("Group2");
x.length = 0;
VarGroup2 = document.getElementById("Group2");
VarGroup2.options[VarGroup2.options.length] = new Option("$group_02_default_option_text","");
document.getElementById("Group2").disabled = true;
}
function CheckGroup1Select()
{
// If no Group1 is selected clear the Group2 and set to default
if(document.getElementById("Group1").value == "")
{
// Clear the Group2 select and set to default value
DefaultGroup2();
}
content;
// Javascript
$group_01_query = "SELECT ".$table_column_01." FROM ".$table." GROUP BY ".$table_column_01;
$group_01_result = mysql_query($group_01_query) or die(mysql_error());
while($group_01 = mysql_fetch_array($group_01_result))
{
$group_01_options .= '<option value="'.$group_01[$table_column_01].'">'.$group_01[$table_column_01].'</option>'."\r\n";
$javascript .=<<<content
else if(document.getElementById("Group1").value == "$group_01[$table_column_01]")
{
// Clear the Group2 and set to default value
DefaultGroup2();
// Set variable options for Group2 select
VarGroup2 = document.getElementById("Group2");
content;
$group_02_query = "SELECT * FROM ".$table." WHERE ".$table_column_01." = '".$group_01[$table_column_01]."' GROUP BY ".$table_column_02;
$group_02_result = mysql_query($group_02_query) or die(mysql_error());
while($group_02 = mysql_fetch_array($group_02_result))
{
$javascript .=' VarGroup2.options[VarGroup2.options.length] = new Option("'.$group_02[$table_column_02].'","'.$group_02[$table_column_02].'");'."\r\n";
}
$javascript .=<<<content
document.getElementById("Group2").disabled = false;
}
content;
}
$javascript .=' }'."\r\n";
} // End of dual_linked_selects function
?>
<?
// execute dual_linked_selects_function
dual_linked_select('type','group1','group2','Select...');
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT type_id FROM type WHERE ???????? LIMIT 1");
while($row = mysql_fetch_array($sql)){
$type_id = $row["type_id"];
}
?>
<html>
<head>
<title>Dual Linked Selects with PHP and MYSQL (without page reload)</title>
<script type="text/javascript" language="JavaScript">
<? echo $javascript; ?>
</script>
</head>
<body>
<br>
<form action="process4.php" method="get" enctype="multipart/form-data">
Maak een keuze:
<br>
<select id="Group1" name="group1" onChange="CheckGroup1Select(this);">
<option value="">Select...</option>
<? echo $group_01_options; ?>
</select>
<br><br>
Maak een keuze
<br><br>
<select id="Group2" name="group2"><? echo $group_01_options; ?></select>
<input type="hidden" name="type_id" value="<?php echo $type_id; ?>">
<input type="submit" value="Submit">
</form>
<br>
</body>
</html>
// Database connection
$db_database = 'xxx';
$db_host = 'localhost';
$db_user = 'xxxxxx';
$db_pass = 'xxxx';
mysql_connect($db_host,$db_user,$db_pass) or die("Could not connect to MySQL (Main connection)");
mysql_select_db($db_database) or die("Could not connect to database (Main connection)");
function dual_linked_select(
$table, // Table to create linked selects from
$table_column_01, // Root category
$table_column_02, // Subcategory of the root category
$group_02_default_option_text // Default option text for the group 2 select
)
{
// Define globals
global $javascript;
global $group_01_options;
// Define variables
$javascript = null; // Hold
$group_01_options = null;//Hold
// Assembly of Javascript starts
$javascript .=<<<content
/* Linked Dropdown Selects Script Start */
function DefaultGroup2()
{
var x = document.getElementById("Group2");
x.length = 0;
VarGroup2 = document.getElementById("Group2");
VarGroup2.options[VarGroup2.options.length] = new Option("$group_02_default_option_text","");
document.getElementById("Group2").disabled = true;
}
function CheckGroup1Select()
{
// If no Group1 is selected clear the Group2 and set to default
if(document.getElementById("Group1").value == "")
{
// Clear the Group2 select and set to default value
DefaultGroup2();
}
content;
// Javascript
$group_01_query = "SELECT ".$table_column_01." FROM ".$table." GROUP BY ".$table_column_01;
$group_01_result = mysql_query($group_01_query) or die(mysql_error());
while($group_01 = mysql_fetch_array($group_01_result))
{
$group_01_options .= '<option value="'.$group_01[$table_column_01].'">'.$group_01[$table_column_01].'</option>'."\r\n";
$javascript .=<<<content
else if(document.getElementById("Group1").value == "$group_01[$table_column_01]")
{
// Clear the Group2 and set to default value
DefaultGroup2();
// Set variable options for Group2 select
VarGroup2 = document.getElementById("Group2");
content;
$group_02_query = "SELECT * FROM ".$table." WHERE ".$table_column_01." = '".$group_01[$table_column_01]."' GROUP BY ".$table_column_02;
$group_02_result = mysql_query($group_02_query) or die(mysql_error());
while($group_02 = mysql_fetch_array($group_02_result))
{
$javascript .=' VarGroup2.options[VarGroup2.options.length] = new Option("'.$group_02[$table_column_02].'","'.$group_02[$table_column_02].'");'."\r\n";
}
$javascript .=<<<content
document.getElementById("Group2").disabled = false;
}
content;
}
$javascript .=' }'."\r\n";
} // End of dual_linked_selects function
?>
<?
// execute dual_linked_selects_function
dual_linked_select('type','group1','group2','Select...');
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT type_id FROM type WHERE ???????? LIMIT 1");
while($row = mysql_fetch_array($sql)){
$type_id = $row["type_id"];
}
?>
<html>
<head>
<title>Dual Linked Selects with PHP and MYSQL (without page reload)</title>
<script type="text/javascript" language="JavaScript">
<? echo $javascript; ?>
</script>
</head>
<body>
<br>
<form action="process4.php" method="get" enctype="multipart/form-data">
Maak een keuze:
<br>
<select id="Group1" name="group1" onChange="CheckGroup1Select(this);">
<option value="">Select...</option>
<? echo $group_01_options; ?>
</select>
<br><br>
Maak een keuze
<br><br>
<select id="Group2" name="group2"><? echo $group_01_options; ?></select>
<input type="hidden" name="type_id" value="<?php echo $type_id; ?>">
<input type="submit" value="Submit">
</form>
<br>
</body>
</html>
Toevoeging op 18/05/2011 19:21:31:
o Ja het gaat om de query die start op regel 91 t/m 97
Wat moet ik achter where zetten om het $type_id te krijgen
Er zijn nog geen reacties op dit bericht.