PHP, jQuery 및 mysql을 사용하는 캐스케이드 메뉴가 있습니다. 그것은 매력처럼 작동하지만 Joomla에서 기사 (PHP 코드를 활성화하는 Joomla 확장 기능을 사용하여)로 가져 오려고하면 제대로 작동하지 않습니다. 문제는, 내가 어디서 문제의 근원을 찾을 지 모르겠다 ... 나는 카테고리를 선택할 수 있지만, 내가 할 때마다 계단식 드롭 다운 메뉴의 두 번째 레벨 (카테고리 -> 타입 -> 모델은 주문)이로드되지 않습니다. 실제로 'Please wait ...'라고 표시되며 몇 초 후에 선택 옵션이 비어 있습니다. 난 안 줌라 프레임 워크에 로컬 호스트 만 계단식 메뉴에서 그것을 테스트 나는 일부 파일을 가지고Joomla 커스텀 PHP, jQuery 모듈
는 ... 일 :
이 script.php -> JQuery와 효과, 또한 드롭 다운 처리합니다
를<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select#type").attr("disabled","disabled");
$("select#model").attr("disabled","disabled");
$("select#category").change(function(){
$("select#type").attr("disabled","disabled");
$("select#type").html("<option>Please wait...</option>");
var id = $("select#category option:selected").attr('value');
$.post("select_type.php", {id:id}, function(data){
$("select#type").removeAttr("disabled");
$("select#type").html(data);
});
});
$("select#type").change(function(){
$("select#model").attr("disabled","disabled");
$("select#model").html("<option>Please wait...</option>");
var id2 = $("select#type option:selected").attr('value');
$.post("select_model.php", {id2:id2}, function(data){
$("select#model").removeAttr("disabled");
$("select#model").html(data);
});
});
$("select#model").change(function(){
var cat = $("select#category option:selected").attr('value');
var type = $("select#type option:selected").attr('value');
var model = $("select#model option:selected").attr('value');
if(cat>0 && type>0 && model >0)
{
var model = $("select#model option:selected").html();
var type = $("select#type option:selected").html();
$("#result").html('<br>Your choice: ' + type + ' ' + model + '.');
}
else
{
$("#result").html("<br>One of the inputs is empty!");
}
return false;
});
});
</script>
<form id="select_form">
Choose category: <select id="category">
<?php echo $opt->ShowCategory(); ?>
</select><br />
Choose type: <select id="type">
<option value="0">Please select...</option>
</select>
<br />
Choose model: <select id="model">
<option value="0">Please select...</option>
</select></form>
<div id="result"></div>
<br><br>
select_type.php -> 사용자가 카테고리를 선택한 후 두 번째 메뉴에서 해당 카테고리의 유형을 표시해야합니다.
<?php
include "class.php";
echo $opt->ShowType();
?>
select_model.php은 -> 선택 유형과 동일하지만,이 유형 선택에 따라, 그래서 이것은 계단식 메뉴의 마지막 수준입니다.
<?php
include "class.php";
echo $opt->ShowModel();
?>
그리고 마지막으로, 나는에서 datas를 가져올 데이터베이스에 연결하는 class.php는 선택 메뉴에서 그들을로드.
<?php
class SelectList
{
protected $conn;
public function __construct()
{
$this->DbConnect();
}
protected function DbConnect()
{
$host = "localhost";
$user = "root";
$password = "usbw";
$db = "test";
$this->conn = mysql_connect($host,$user,$password) OR die("error!");
mysql_select_db($db,$this->conn) OR die("error!");
return TRUE;
}
public function ShowCategory()
{
$sql = "SELECT * FROM categories";
$res = mysql_query($sql,$this->conn);
$category = '<option value="0">Please select a category...</option>';
while($row = mysql_fetch_array($res))
{
$category .= '<option value="' . $row['id_cat'] . '">' . $row['name'] . '</option>';
}
return $category;
}
public function ShowType()
{
$sql = mysql_query("SELECT * FROM type WHERE id_cat=$_POST[id]");
$res = mysql_query($sql,$this->conn);
$type = '<option value="0">Please select a type...</option>';
while($row = mysql_fetch_array($sql))
{
$type .= '<option value="' . $row['id_type'] . '">' . $row['name'] . '</option>';
}
return $type;
}
public function ShowModel()
{
$sql = "SELECT * FROM model WHERE id_model=$_POST[id2]";
$res = mysql_query($sql,$this->conn);
$model = '<option value="0">Please select a model...</option>';
while($row = mysql_fetch_array($res))
{
$model .= '<option value="' . $row['id_model'] . '">' . $row['name'] . '</option>';
}
return $model;
}
}
$opt = new SelectList();
?>
감사를하는 데 도움이! 내가 먼저 Sourcerer를 시도합니다 ... 나는 mysql_connect를 사용해서는 안된다는 것을 알고 있지만 이것은 단지 테스트 단계이며, 심지어 그것이 workig인지를보고 싶습니다 ...하지만 실제로는 아닙니다. 비슷한 확장 기능을 찾으려고 노력할 것입니다.하지만 멀티 캐스팅 메뉴 시스템이 있다면 정말 의심 스럽습니다. – egyeneskanyar
당신은 최선을 다해 올바른 코딩 표준을 사용하여 테스트하면 나중에 모든 것을 변환하지 않아도됩니다.) – Lodder