0

最初のドロップ ボックスから 2 番目のドロップ ボックスを除外しようとしています。最初のもの$box1は正常に動作します。$box2しかし、私は最初から構築することはできません。私が変われば

SELECT Site FROM companiesandsitessql WHERE Company ='$box1'"); 

SELECT Site FROM companiesandsitessql WHERE Company =”CompanyA);

次に、CompanyA のすべてのサイトを 2 番目のボックスにプルします。の多くのバリエーションを試しまし$box1たが、何かが欠けているに違いありません。どんなアイデアでも大歓迎です。

<?php
$dbhost  = 'localhost';
$dbname  = 'escalations';
$dbuser  = 'root';

$con = mysql_connect($dbhost, $dbuser);
 {
    $box1 = array();
    mysql_select_db('escalations');
    $result = mysql_query("SELECT distinct Company FROM companiesandsitessql");
    while($row = mysql_fetch_array($result)) { $box1[] = $row; }

}
/* Generate select box contents */
$out1 = '<select name="box1">';
$out1 .= '<option>Select Company</option>';
if (!empty($box1)) {
foreach ($box1 as $k => $v) {
    $out1 .= '<option value="'.$v['Company'].'">'.$v['Company'].'</option>';
    }
}
$out1 .= '</select>';
/* Output */
echo $out1;


 {
$box2 = array();
    mysql_select_db('escalations');
    $result2 = mysql_query("SELECT Site FROM companiesandsitessql WHERE Company        ='$box1'");
    while($row2 = mysql_fetch_assoc($result2)) { $box2[] = $row2; }

}
/* Generate select box contents */
$out2 = '<select name="box2">';
$out2 .= '<option>Site list</option>';
if (!empty($box2)) {
    foreach ($box2 as $k1 => $v) {
        $out2 .= '<option value="'.$v['Site'].'">'.$v['Site'].'</option>';
    }
}
$out2 .= '</select>';
/* Output */
echo $out2;

?> 
4

1 に答える 1

0
Figured it out, here’s the code.

***File new.php***

<?php
$dbhost  = 'localhost';
$dbname  = 'escalations';
$dbuser  = 'root';

$con = mysql_connect($dbhost, $dbuser);
?>
<html>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

function autoSubmit() {
$.post('dropoutput.php', { name: box1form.CompanyName.value},
 function (output) {
    $('#info').html(output).show();
    });
    }
</script>

<body>
<form name="box1form" action="insert.php" method="post">
<?php

{
 $box1 = array();
 mysql_select_db('escalations');
 $result = mysql_query("SELECT distinct Company FROM companiesandsitessql ORDER BY Company ASC");
 while($row = mysql_fetch_array($result)) { $box1[] = $row; }

 }
/* Generate select box contents */
$CompanyName = '<select name="CompanyName" onchange="autoSubmit()">';
$CompanyName .= '<option selected="selected">Select Company</option>';
if (!empty($box1)) {
 foreach ($box1 as $k => $v) {
    $CompanyName .= '<option value="'.$v['Company'].'">'.$v['Company'].'</option>';
  }
 }
$CompanyName .= '</select>';
/* Output */
echo $CompanyName;

?>

<div id="info"></div><input name="send" type="submit" value="submit"><br>
</form>
</body>
</html>

***file dropoutput.php***

<?php
mysql_connect("localhost", "root", "") or die (mysql_error ());

$name = mysql_real_escape_string($_POST['name']);

{
$box2 = array();
 mysql_select_db('escalations');
$result2 = mysql_query("SELECT Site FROM companiesandsitessql WHERE Company ='$name' ORDER BY Site ASC");
while($row2 = mysql_fetch_assoc($result2)) { $box2[] = $row2; }

}
 /* Generate select box contents */
 $S = '<select name="SiteOptions[]" multiple="multiple">';
 $S .= '<option>Site list</option>';
 if (!empty($box2)) {
  foreach ($box2 as $k1 => $v) {
    $S .= '<option value="'.$v['Site'].'">'.$v['Site'].'</option>';
  }
 }
$S .= '</select>';
/* Output */
echo $S;

?>

 ***file  insert.php...

<?php
$dbhost  = 'localhost';
$dbname  = 'escalations';
$dbuser  = 'root';
$dbpass  = '';

$con = mysql_connect($dbhost, $dbuser);

if($con == FALSE)
{
echo 'Cannot connect to database' . mysql_error();
}
else
{
 echo " Connected to database: ";
}

$Site = implode(', ', $_POST['SiteOptions']);


mysql_select_db("escalations", $con);
$sql="INSERT INTO escalationtrackersql (CompanyName, Site)
VALUES
('$_POST[CompanyName]', '$Site')";

echo "Added $_POST[CompanyName] ";
print $Site;

if (!mysql_query($sql, $con))
{
die('Error: ' . mysql_error());
}

echo "  : Escalation request successfully entered.";

mysql_close($con)

?>

<html>
<head>
<meta content="en-us" http-equiv="Content-Language">
</head>
<body bgcolor="#C0C0C0">
<p>&nbsp;</p>
<p><a href="new.php">Return to the 
  escalation request form</a>.</p>

  </html>
于 2013-02-05T18:33:26.330 に答える