2012-04-19 41 views
1

我從這個網站偉大的祕訣,但與現在的東西真的很掙扎,需要一些專家的幫助,我學習,所以請好的:-)無論如何,我有一個腳本,動態變化3下拉菜單取決於用戶選擇什麼,我有一個數據庫與一個表,我可以查詢沒有問題(MySQL)迄今如此好,問題是,我似乎無法產生的結果基於用戶從下拉菜單中,我沒有看到任何記錄,我甚至不知道如果我可以與具有數字我的菜單項,而不是文字中使用的查詢,我將不勝感激,甚至一個小的幫助,我只需要得到那麼一位工作我想我可以管理=非常感謝所有查詢MySQL數據庫從動態下拉菜單

<?php 
// Make a MySQL Connection 
mysql_connect("localhost", "", "") or die(mysql_error()); 
mysql_select_db("travel") or die(mysql_error()); 


$valid_class = array('4', '6', '7', '1', '5', '3'); 
$valid_category = array('4.1.9', '4.1.7', '4.1.8', '4.1.6', '4.1.5', 
'4.1.2', '4.1.1', '4.1.10', '4.1.4'' 4.1.3',); 

$where = array(); 
$where[] = 'menuOne = "' . mysql_real_escape_string($_POST['menuOne']) . '"'; 
; 

if (in_array($_POST['menuOne'], $valid_class)) 
{ 
$where[] = 'menuOne = "' . $_POST['menuOne'] . '"'; 
} 

if (in_array($_POST['menuTwo'], $valid_category)) 
{ 
$where[] = 'menuTwo = "' . $_POST['menuTwo'] . '"'; 
} 
// Retrieve all the data from the "category" table 
$result = 'SELECT * FROM records WHERE ' . implode(' AND ', $where); 



     if(!isset($result)) 
{ 
mysql_affected_rows($result); 

} 
echo "\n <table border=1 width=100%>"; 

     echo "\n<tr>" . 
      "\n\t<th>ID</th>" . 
      "\n\t<th>Name</th>" . 
      "\n\t<th>Address</th>" . 
      "\n\t<th>Location</th>" . 
      "\n\t<th>Email</th>" . 
      "\n\t<th>Telephone</th>" . 
      "\n\t<th>Website</th>" . 
      "\n\t<th>Open Season</th>" . 
      "\n\t<th>Destination</th>" . 
      "\n\t<th>Categories</th>" . 

      "\n</tr>"; 

     while($row = @ mysql_fetch_array($result)) { 

      echo "\n<tr>" . 
       "\n\t<td>{$row["ID"]}</td>" . 
       "\n\t<td>{$row["Name"]}</td>" . 
       "\n\t<td>{$row["Address"]}</td>" . 
       "\n\t<td>{$row["Location"]}</td>" . 
       "\n\t<td>{$row["Email"]}</td>" . 
       "\n\t<td>{$row["Telephone"]}</td>" . 
       "\n\t<td>{$row["Website"]}</td>" . 
       "\n\t<td>{$row["Open Season"]}</td>" . 
       "\n\t<td>{$row["Destination"]}</td>" . 
       "\n\t<td>{$row["Categories"]}</td>"; 

     } 
     echo "\n</table>"; 





?> 

回答

0

爲了讓您的MySQL查詢

$result = 'SELECT * FROM records WHERE ' . implode(' AND ', $where);

工作,你需要實際發送。

mysql_query($result)

你有什麼目前

while($row = @ mysql_fetch_array($result)) {

被設計爲在msql_query調用的結果運行。例如

$query= mysql_query($result);

然後運行

while($row = @ mysql_fetch_array($query)) {

所以就我所看到的,你剛纔離開了查詢那你唯一的問題。

希望幫助,隨時要求更多的細節。

+0

嗨SpeedCrazy,非常感謝你的幫助的答覆昨天,我無法把我的感謝,但它做的意義了很多,我已經改變了我的方法AA一點,但仍然不知道爲什麼我不能拉記錄出來的MySQL從數組,我可以選擇*沒問題,只是無法得到我想要的數組中的值。 – 2012-04-20 09:47:26

+0

你究竟是什麼意思?我所做的就是把他們從數組中拉出來。使用'mysql_query()'從數據庫中獲取數據,然後運行'mysql_fetch_array()'格式化數據中的數據,如果沒有前者,就不能執行後者。如果你的意思是你不能通過列名訪問數據,可以使用'mysql_fetch_assoc()'來設置關聯數組中的數據。 – SpeedCrazy 2012-04-21 03:00:31

+0

再次感謝您的幫助阿米戈,我覺得我所試圖做的是上面我目前的技能集的話,我可能剛剛從東西從頭開始,這不是基於動態菜單上開始改變,並有另一慶典它這一次我能得到更簡單的工作。 再次感謝 韋斯 – 2012-04-21 12:41:13