开发者

retrieve and display multiple mysql records with jquery

This is what I have got. It displays just one single record. Can anyone please tell me how can I retrieve multiple records from the table.

$.getJSON('getinfo.php', { id:id }, parseInfo);
function parseInfo(data) {
    $('div#info').html(data.name +': '+ data.title); 
}

The getinfo.php part is as follows:开发者_如何学C

$id = (isset($_GET['id']) && !empty($_GET['id'])) ? $_GET['id'] : 0;
$id = trim($id);

$result = mysql_query("SELECT * FROM tab WHERE col=\"$id\" );
while ($row = mysql_fetch_assoc($result)) {
    $test[$id] = array('name' => $row["name"], 'title' => $row["title"]);
}

Many thanks in advance. DJ


$id never changes, so you keep rewriting the same entry. Did you perhaps want $test[$id] = Array() outside the loop, and $test[$id][] = ... inside?


Maybe you should start by making your page work without javascript & AJAX. What is the purpose of this page? Is $id is a unique/a key in the database?

For me, the AJAX is just a progressive enhancement. The page in my application should working without javascript enabled. When javascript enabled, then I add a fancy features using AJAX & jQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜