donmqryh49993 2012-12-27 18:49
浏览 32

从3个下拉菜单中获取数据,并根据这3个参数从db填充4

I need to know what is wrong. The PHP doesn't return anything. I think the variables don't get on the PHP file. Please help me to find out what goes wrong.

<?php
defined('_JEXEC') or die;
$db = JFactory::getDbo();
$an=$_POST['an'];
$fac=$_POST['fac'];
$uni=$_POST['uni']; 

$result1 = mysql_query("SELECT * FROM drv_uni_$uni WHERE an='$an'");

while($row = mysql_fetch_array($result1)){
     $display_string = "<option value=\"".$row['materie']."\">". $row['materie'] ."</option>";
}
     echo $display_string;
?>

Javascript

function  getValFromDb() {
    var valoare_selectata_uni = document.getElementById('category').value;
    var valoare_selectata_fac = document.getElementById('subcategory').value;
    var valoare_selectata_an = document.getElementById('an').value;
    var url = "modules/mod_data/tmpl/script.php";
    var params = 'uni=' + valoare_selectata_uni + 
                 '&fac=' + valoare_selectata_fac +
                 '&an=' + valoare_selectata_an;

    if (window.XMLHttpRequest) { 
        AJAX=new XMLHttpRequest(); 
    } else { 
        AJAX=new ActiveXObject("Microsoft.XMLHTTP"); 
    }

    if (AJAX) {
        AJAX.open("POST", url, false);
        AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        AJAX.onreadystatechange = function() {
            if(AJAX.readyState == 4 && AJAX.status == 200) {
                var answer = AJAX.responseText;
                document.getElementById('materie').innerHTML = answer;
            }
        }; 
        AJAX.send(params);
    }
}
  • 写回答

1条回答 默认 最新

  • dongpo3957 2012-12-28 02:56
    关注

    You can debug the code using below few methods.

    1. You can 1st print_r($result1) and see whether your SQL returns the results you want. If not try working on the query.

    2. $display_string = "<option value=\"".$row['materie']."\">". $row['materie'] ."</option>"; is wrong you should have a it like below. $display_string .= "<option value=\"".$row['materie']."\">". $row['materie'] ."</option>";. You are missing .=

    3. if had static variables and included on the main it shows good. Rather than using $_POST use Joomla's way of retrieving POST data JRequest::getVar('an');. Read more

    let me know the results I might be able to help you.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思