2012-04-19 45 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