0

i'm using this code for post text of option tag :

$("#major_names").change(function () {
    $.post('find_lesson.php',  { dars:$("#major_names option:selected").text() },
        function(data){ 
            if (data.success)
                        $("div").append(data.doroos);
            else
                alert('mm');
        },'json'); 
return false; 
});

now in find_lesson file i use this code for fetch any record from database

<?php

$lessonName=$_POST['lesson '];
$query= mysql_query("SELECT * FROM at_*** WHERE title = '{$lessonName}'");
$result= mysql_fetch_array($query);

$sql= mysql_query("SELECT * FROM  *** JOIN at_lessons ON  . . .");
while($result=mysql_fetch_assoc($sql))
{
$data ['doroos']= $result['title'];
}
$data['success']=true;


echo json_encode($data);

?>

mysql command is correct but after send array i have getting 1 record. please help me

4

2 回答 2

5

改变

$data ['doroos']= $result['title'];

$data ['doroos'][] = $result['title'];

您基本上是在覆盖doroos. 相反,使用[]将每个添加$result['title']doroos.

于 2012-08-08T08:29:32.670 回答
0

您应该改为执行以下操作。否则,“doroos”将仅具有提取结果集中的最后一个标题记录。

<?php

$lessonName=$_POST['lesson '];
$query= mysql_query("SELECT * FROM at_*** WHERE title = '{$lessonName}'");
$result= mysql_fetch_array($query);

$sql= mysql_query("SELECT * FROM  *** JOIN at_lessons ON  . . .");

$doroos = array();
$x = 0;
while($result=mysql_fetch_assoc($sql))
{    
     $doroos[x++] = $result['title'];
}
$data ['doroos']= $doroos;
$data['success']=true;


echo json_encode($data);

?>
于 2012-08-08T08:34:34.533 回答