json_encode not working inside while loop
<p>I have a json_encode in my php script which seems to fail the Jquery side of things if the json_encode is called inside a while loop.</p>

<p>When i view the result in a browser window other than the page i need the result in i can see that it does actually does work.</p>

<p><strong>For example:</strong></p>

<pre><code>while ($row = mysql_fetch_array($result)) {     
    $id = $row['id'];
    $title = $row['title'];
    $content = $row['content'];

    $data = array("id" =&gt; $id,
    "title" =&gt; $title,
    "success" =&gt; true
    );
echo json_encode($data); // Inside the While Loop

}
</code></pre>

<p><strong>and the output in the browser is:</strong></p>

<pre><code>{"id":"15","title":"Advanced Booking Examples","success":true}
{"id":"14","title":"Advanced Booking Fields","success":true}
{"id":"11","title":"Add New Driver","success":true}
{"id":"10","title":"Registering a Driver \/ Add New Vehicle","success":true}
{"id":"8","title":"Dispatch Controls","success":true}
{"id":"7","title":"Troubleshooting Driver Device Checklist","success":true}
{"id":"6","title":"Requirements Checklist","success":true}
</code></pre>

<p>In the jQuery response this is actually blank but if I leave the <code>echo json_encode($data);</code> just outside the while loop the jQuery picks up the response, however only 1 record - being the last record in the loop.</p>

<p>I need the jQuery to pick up all results from the loop.</p>

<p><strong>Here's the JS</strong></p>

<pre><code>$.ajax({ // Send it off for prcessing
        type: "POST",
        dataType: 'json',
        url: "includes/auto_suggest.php",
        data: {
            q: inputString
        },
        success: function (result) {
            if (result.success) {             
                var id = result.id;
                var title = result.title;                    
                $('#auto_id').append("&lt;input type='text' class='hideid' id='hideid_" + id + "' value='" + id + "'/&gt;");              
        $('#auto_title').prepend("&lt;p&gt;" + title + "&lt;/p&gt;");
            }
        }
    });
</code></pre>

<p>Any ideas?</p>

<p>Thanks in advance</p>
