我有这个我无法解决的问题。部分原因是我无法用正确的术语来解释它。我是新手,很抱歉这个笨拙的问题。
下面你可以看到我的目标概述。我试图在动态下拉列表中获取所有类别 ID,第二个下拉列表基于第一个下拉列表选择,我发现一些代码在本地工作正常,但我尝试在里面magento 它不工作为什么?
这是我的代码
<tr>
<td class="tdpadfirst">
<label for="category" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Category') ?>:</label>
<span class="required starimp"> </span>
</td>
<td class="tdpadfirst">
<select id="category" class="myinput-text required-entry widthinput" name="category" onChange="updateCategory(this.value)">
<option value="">--Select Categories--</option>
<?php
include('db.php');
$sql=mysql_query("select entity_id from catalog_category_entity where level='2';");
while($row=mysql_fetch_array($sql)) {
$id=$row['entity_id'];
$data=$row['parent_id'];?>
<!--echo '<option value="'.$entity_id.'">'.$parent_id.'</option>';-->
<option value="<?php echo $id ?>"><?php echo $id ?></option>
<?php } ?>
</select>
<select name="city" class="city">
<option selected="selected">--Select subcategory--</option>
</select></td></tr>
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".country").change(function() {
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax ({
type: "POST",
url: "ajax_city.php",
data: dataString,
cache: false,
success: function(html) {
$(".city").html(html);
}
});
});
});
ajax_city.php 是:
<?php
include('db.php');
if($_POST['id']) {
$id=$_POST['id'];
$sql=mysql_query("select entity_id from catalog_category_entity where parent_id='$id'");
while($row=mysql_fetch_array($sql)) {
$id=$row['entity_id'];
$data=$row['parent_id'];
echo '<option value="'.$data.'">'.$id.'</option>';
}
}
?>
db.php 是:
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "admin";
$mysql_database = "magento16";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
?>