我有一些困難,我的「選擇」有兩個SQL查詢選擇下拉
在我的選擇/菜單,我顯示所有的選項在我的數據庫來自一個表(table_db_email)
在此表(tb_code_prmtn11_email)我有兩個領域: fld_email_id fld_name_email
它的工作原理這裏是一個代碼
<select name="email_adress_menu" id="email_adress_menu" class="valid" onchange="submit()">
<?php
echo "<option selected=\"selected\" value=''>Choose your name</option>";
$req_email_adress_menu = "SELECT DISTINCT id_email, fld_name_email, fld_adresse_email FROM $table_db_email ORDER BY fld_name_email ";
$rep_email_adress_menu = mysql_query($req_email_adress_menu, $cnx) or die(mysql_error()) ;
while($show_email_adress_menu = mysql_fetch_assoc($rep_email_adress_menu)) {
echo '<option value="'.$show_email_adress_menu['id_email'].'"';
//if($primes==$show_email_adress_menu['fld_name_email']){echo " selected";} //display to select an option!!!!!!!!!!!!!!!!
echo '>'.$show_email_adress_menu['fld_name_email'].' - '.$show_email_adress_menu['fld_adresse_email'].'</option>';
}
?>
</select>
我有一些其他的信息,從另一個表來:tb_code_prmtn11(含有關人員的信息)
我有幾個領域:
- id_resultat
- fld_name
- fld_email_id; (外鍵(
fld_email_id
)參考文獻tb_code_prmtn11_email
(id_email
)ON DELETE NO ACTION ON UPDATE CASCADE;)
我想把這個菜單中的其他網頁上,該選擇必須顯示所有如下選項(帶)通過選擇匹配在第二表中找到的信息的選項:tb_code_prmtn11
我該怎麼做?
SELECT td.id_resultat,td.fld_email_id,email.fld_name_email
FROM $table_db td
JOIN $table_db_email email ON td.fld_email_id = email.id_email
WHERE td.id_resultat = $id
此代碼的工作也,但我不知道我怎麼能包括我的菜單本次查詢...
你的代碼工作... 我看到我的選擇:它作品...它顯示所有的選項但沒有選擇的選項。
所以第二查詢工作:(這是第42行)
我得到在FireFox下面的代碼:
27 <form id="form-fan" method="post" action="edit.php">
<option value="tomo">TOTO MONO - [email protected]</option>
<option value="kito">KIKI TOTO - [email protected]</option>
所以我想顯示選項選擇與其他選項,但我不能... 我的菜單工作,但任何選項被選中,但是,在現實中,有一個選項,因爲在我的數據庫中,每個有一個
我試過我的第一個查詢(你的/我的代碼中的第18行)
SELECT tbl.id_resultat,tbl.fld_email_id,email.fld_nom_email,email.id_email
FROM tb_code_prmtn11 tbl
INNER JOIN tb_code_prmtn11_email email
ON tbl.fld_email_id = email.id_email
WHERE tbl.id_resultat='27'
* $ table_db TBL * =>tb_code_prmtn11
* $ table_db_email * - >tb_code_prmtn11_email
和它的工作... ** id_resultat:27
fld_email_id:KITO
fld_nom_email:KIKI TOTO
id_email:KITO **
所以,我怎麼能顯示與選擇正確的選項其他選項在我的選擇? 我怎麼可以在Firefox得到下面的代碼:
<option value="tomo">TOTO MONO - [email protected]</option>
<option value="kito" selected>KIKI TOTO - [email protected]</option>
我檢查我的變量ID:這是確定... 這裏是我的改變你的新代碼來適應我的網頁:
<?php
include"../bd_db/connection.php";
include"../bd_db/selection.php";
$id=$_GET['id'];
echo $id;
if (isset($_POST) && !empty($_POST))
{
if (array_key_exists('ajaxId', $_POST))
{
if ((int)$_POST['ajaxId'] <= 0)
{
throw new Exception("go to hell");
}
$query = "SELECT td.id_resultat as id, email.fld_name_email AS name FROM " . $table_db . " td INNER JOIN " . $table_db_email . " email ON td.fld_email_id = email.id_email WHERE td.id_email = " . $_POST['ajaxId']; //!!!!! line 18
$result = mysql_query($query, $cnx);
if (mysql_num_rows($result) > 0)
{
$data = array();
while ($row=mysql_fetch_array($result))
{
$data[$row["resultat"]] = $row["name"];
}
echo json_encode($data);
exit();
}
}
if (array_key_exists('select-big-fan', $_POST))
{
// you've found a big fan selected
}
}
$query = "SELECT DISTINCT id_email AS id, fld_nom_email AS name, fld_adresse_email AS email FROM " . $table_db_email . " ORDER BY name"; //second query works :(line 42)
$result = mysql_query($query, $cnx);
?>
<?php if (mysql_num_rows($result) > 0) : ?>
<form id="form-fan" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
<select name="select-fan" id="select-fan">
<?php while ($row=mysql_fetch_array($result)) : ?>
<option value="<?php echo $row["id"] ?>"><?php echo $row["name"] ?> - <?php echo $row["email"] ?></option>
<?php endwhile ?>
</select>
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#select-fan").change(function(){
var fanId = jQuery(this).val();
jQuery.ajax(function(){
url: "<?php echo $_SERVER["PHP_SELF"] ?>",
data: {ajaxId: fanId},
success: function(data){
selectBigFan = jQuery('<select>', {name: 'select-bigfan', id: 'select-bigfan'});
jQuery.each(data, function(bigFanId, bigFanText){
optionBigFan = jQuery('<option>' {value: bigFanId, text: bigFanText});
optionBigFan.appendTo(selectBigFan);
});
selectBigFan.insertAfter(jQuery('#select-fan'));
jQuery('<input>', {type: 'submit', value: 'send'});
}
});
});
});
</script>
<?php else : ?>
<p>Yup, there's nothing here, do u have beer ?</p>
<?php
endif
?>
有一個愉快的一天
這裏是我的改變你的代碼爲適應我的網頁...
<?php
include"../bd_db/connection.php";
include"../bd_db/selection.php";
$id=$_GET['id'];
echo $id;
if (isset($_POST) && !empty($_POST))
{
if (array_key_exists('ajaxId', $_POST))
{
if ((int)$_POST['ajaxId'] <= 0)
{
throw new Exception("go to hell");
}
$query = "SELECT td.id_resultat as id, email.fld_nom_email AS name FROM " . $table_db . " td INNER JOIN " . $table_db_email email ON td.fld_email_id = email.id_email WHERE td.fld_email_id = " . $_POST['ajaxId']"; //!!!!! la ligne 19
$result = mysql_query($query, $cnx);
if (mysql_num_rows($result) > 0)
{
$data = array();
while ($row=mysql_fetch_array($result))
{
$data[$row["resultat"]] = $row["name"];
}
echo json_encode($data);
exit();
}
}
if (array_key_exists('select-big-fan', $_POST))
{
// you've found a big fan selected
}
}
$query = "SELECT DISTINCT id_email AS id, fld_nom_email AS name, fld_adresse_email AS email FROM " . $table_db_email . " ORDER BY name";
$result = mysql_query($query, $cnx);
?>
<?php if (mysql_num_rows($result) > 0) : ?>
<form id="form-fan" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
<select name="select-fan" id="select-fan">
<?php while ($row=mysql_fetch_array($result)) : ?>
<option value="<?php echo $row["id"] ?>"><?php echo $row["name"] ?> - <?php echo $row["email"] ?></option>
<?php endwhile ?>
</select>
</form>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#select-fan").change(function(){
var fanId = jQuery(this).val();
jQuery.ajax(function(){
url: "<?php echo $_SERVER["PHP_SELF"] ?>",
data: {ajaxId: fanId},
success: function(data){
selectBigFan = jQuery('<select>', {name: 'select-bigfan', id: 'select-bigfan'});
jQuery.each(data, function(bigFanId, bigFanText){
optionBigFan = jQuery('<option>' {value: bigFanId, text: bigFanText});
optionBigFan.appendTo(selectBigFan);
});
selectBigFan.insertAfter(jQuery('#select-fan'));
jQuery('<input>', {type: 'submit', value: 'send'});
}
});
});
});
});
</script>
<?php else : ?>
<p>Yup, there's nothing here, do u have beer ?</p>
<? php
endif
?>
我有一個來自行18
Parse error: syntax error, unexpected T_STRING in C:\inetpub\wwwroot\byrd\apps_code_promotion\verification\edit.php on line 18
所以我用下面這行也嘗試錯誤信息,但我有同樣的錯誤信息:
$query = "SELECT td.id_resultat as id, email.fld_nom_email AS name FROM " . $table_db . " td INNER JOIN " . $table_db_email email ON td.fld_email_id = email.id_email WHERE td.fld_email_id = " . $_POST['ajaxId']"; //!!!!! la ligne 19
$query = "SELECT td.id_resultat as id, email.fld_nom_email AS name FROM " . $table_db . " td INNER JOIN " . $table_db_email email ON td.fld_email_id = email.id_email WHERE td.fld_email_id = . $_POST['ajaxId']; //!!!!! la ligne 19
爲什麼必須選擇第二個選項?因爲我們有兩個屏幕(文件)和一個下拉菜單: 在第一個畫面,我顯示在用戶的所有信息:
<?php
$req= " select tbl.id_resultat,schl.fld_school,tbl.fld_note,email.fld_nom_email,email.fld_adresse_email
FROM $table_db tbl
INNER JOIN $table_db_school schl
ON tbl.fld_school_id = schl.fld_id_school
INNER JOIN $table_db_email email
ON tbl.fld_email_id = email.id_email";
$rep = mysql_query($req, $cnx) or die(mysql_error()) ;
while($row=mysql_fetch_row($rep)){
$id_resultat=$row[0];
$fld_school=$row[1];
$fld_note=$row[2];
$fld_nom_email=$row[3];
$fld_adresse_email=$row[4];
echo "<tr ><td>$id_resultat</td><td>
$fld_shool</td><td>
$fld_note</td><td>
$fld_nom_email</td><td>
$fld_adresse_email</td><td>
<a href=\"edit.php?id=$id_resultat\">to verify</a></td>
</tr>"
?>
在第二個屏幕,(當鏈路上的「用戶的點擊」驗證」 ')他可以在下拉菜單中看到選擇的選項,如果需要的話,他可以選擇其他選項(電子郵件...)
那麼如何在我的選擇中顯示與其他選項一起選擇的正確選項?
我希望這僅僅是諷刺... – MJB
喜奔,我該怎麼辦呢?用Ajax查詢SQL?你有一個可以激勵我的例子嗎? – aspkiddy