Script combineren?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Koosje Derks

Koosje Derks

31/12/2007 12:33:00
Quote Anchor link
Hallo,

als onbekende in php wil graag twee scripts combineren welke van phphulp komen, nl deze;

<FORM METHOD=\"POST\" ACTION=\"factsheet.php\">
Search:<br>
<select class=\"searchinput\" name=\"zoekterm\" size=\"1\" cols=\"50\">

<option value=\"woord\">Woord</option>
</select>
<input type=\"submit\" class=\"button\" name=\"submit\" value=\"submit\">


Ik werk nu met bovenstaande geval "zoekterm" wordt gestuurd naar factsheet.php als $HTTP_POST_VARS[zoekterm], waarin de select sql procedures staan.

So far, so good. Is dit te combineren met het dual select van deze forum:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?
// Database connection
$db_database = 'databasename';
$db_host = 'localhost';
$db_user = 'username';
$db_pass = 'password';
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 ".$table_column_02." 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
?>


Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?
// execute dual_linked_selects_function
dual_linked_select('tabel_name','table_column1','tablecolumn2','Select...');
?>


<html>
<head>
<title>Dual Linked Selects with PHP and MYSQL (without page reload)</title>
<script type="text/javascript" language="JavaScript">
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<? echo $javascript; ?>

</script>
</head>

<body>
<form action="">
Group1:
<br>
<select id="Group1" name="group1" onchange="CheckGroup1Select(this);">
<option value="">Select...</option>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<? echo $group_01_options; ?>

</select>

<br>
Group2:
<br>
<select id="Group2" name="group2"></select>

</form>
</body>

</html>

waarbij de tekst in de tweede select box automatisch zoekt naar een andere database via de factsheet in het eerste voorbeeld?

m.vr.gr
 
Er zijn nog geen reacties op dit bericht.



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.