日期:2014-05-17 浏览次数:20541 次
<?php /* Created on [2012-5-16] Author[yushuai.niu] */ #查询标题信息 $sql="select * from table"; $res=mysql_query($sql); if(!$res) die("SQL: {$sql} <br>Error:".mysql_error()); if(mysql_affected_rows() > 0){ $titles = array(); while($rows = mysql_fetch_array(MYSQL_ASSOC)){ array_push($titles,$rows); } } ?> <table border=1> <?php foreach($titles as $row_Recordset_task){ ?> <tr> <td> <a href="javascript:void(0)" onclick="record(<?=$row_Recordset_task['TID']?>)" > <?=$row_Recordset_task['csa_title']?> </a> </td> </tr> <?php } ?> </table> <div id="show"></div> <script> //Ajax var xmlHttp; function createXMLHttpRequest() { if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } function record(id){ createXMLHttpRequest(); url = "action.php?id="+id+"&ran="+Math.random(); method = "GET"; xmlHttp.open(method,url,true); xmlHttp.onreadystatechange = showList; xmlHttp.send(null); } function show(){ if (xmlHttp.readyState == 4){ if (xmlHttp.status == 200){ var text = xmlHttp.responseText; document.getElementById("show").innerHTML = text; }else { alert("response error code:"+xmlHttp.status); } } } </script> <?php #action.php if(isset($_GET['id'])){ $sql="select * from table where id=".$_GET['id']; $res=mysql_query($sql); if(!$res) die("SQL: {$sql} <br>Error:".mysql_error()); if(mysql_affected_rows() > 0){ $rows = mysql_fetch_array(MYSQL_ASSOC); } print_r($rows); mysql_close(); } ?>
------解决方案--------------------
学习了