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

2 Answers 2

5

Change

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

to

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

You are basically overwriting the doroos. Instead, use [] to add every $result['title'] to doroos.

Sign up to request clarification or add additional context in comments.

2 Comments

hello. after change it i getting this error in firebug : NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild] [Break On This Error] fragment.appendChild( script );
It's a javascript error. do alert(data.doroos) and tell what you get.
0

You should do something like below instead. Otherwise "doroos" will only have the last title record from the fetched resultset.

<?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);

?>

2 Comments

i have get this error now: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild] [Break On This Error] fragment.appendChild( script ); jquery-latest.js (line 6497) POST aou.ir/ivu/assessment/find_dars.php 200 OK 35ms jquery-latest.js (line 8240) HeadersPostResponseHTMLJSONCookies {"doroos":[],"success":true}
after change code to this: $data['doroos'] = array(); $x = 0; while($result=mysql_fetch_assoc($sql)) { $data['doroos'][$x++] = $result['title']; } $data['success']=true; echo json_encode($data); ?> i can get this result in firebug: {"doroos":["\u0627\u0646\u0633\u0627\u0646 \u0634\u0646\u0627\u0633\u06cc"],"success":true} but i can't show that with this line: if (data.success) $("div").append(data.doroos);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.