我想要的效果是
<table>
<?php $i=1;
do { ?>
<tr>
//标题
<td><a href="default_task_edit.php?editID=<?php echo $row_Recordset_task['TID']; ?>" ><?php echo $row_Recordset_task['csa_title']; ?></a></td>
</tr>
<?php $i=$i+1;
} while ($row_Recordset_task = mysql_fetch_assoc($Recordset_task));
?>
</table>
</td>
<td rowspan="2" width="80%" align="center"><?php echo $multilingual_neirong; ?>
//在这里显示标题所相关的内容,内容在在、数据库的值为$row_Recordset_task['csa_text']
</td>
<table>
<?php $i=1;
do { ?>
<tr>
//标题
<td><a href="default_task_edit.php?editID=<?php echo $row_Recordset_task['TID']; ?>" ><?php echo $row_Recordset_task['csa_title']; ?></a></td>
</tr>
<?php $i=$i+1;
} while ($row_Recordset_task = mysql_fetch_assoc($Recordset_task));
?>
</table>
</td>
<td rowspan="2" width="80%" align="center"><?php echo $multilingual_neirong; ?>
//在这里显示标题所相关的内容,内容在在、数据库的值为$row_Recordset_task['csa_text']
</td>
$row_Recordset_task = mysql_fetch_assoc($Recordset_task);
do { ?>
<?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();
}?>
do {
$titles = array();
array_push($titles,$row_Recordset_task);
//$row_Recordset_task 已定义没问题
}while($row_Recordset_task = mysql_fetch_assoc($Recordset_task));
?>
<table border="1">
<?php
foreach($titles as $rows){ ?>
<tr>
<td>
<a href="javascript:void(0)" onclick="record(<?=$rows[TID]?>)" >
<?=$rows[csa_title]?>
</a>
</td>
</tr>
<?php }
这样写怎么还是不对,不输出值
do……while 是指:在执行while语句的内容之前,先进行do中的内容。
这里没有加do的必要!
直接按照#11的写法就行了,只需要修改你的sql执行语句。
http://download.csdn.net/detail/dmtnewtons/4122897
不过现在那块没问题了
这样写的
<?php
$titles = array();
do {
array_push($titles,$row_Recordset_task);
#$row_Recordset_task获取数据库值,已定义
}while($row_Recordset_task = mysql_fetch_assoc($Recordset_task));
?><table border="1" width="100%">
<?php
$i=1;
foreach($titles as $val){ ?>
<tr>
<td align="center">
<a href="javascript:void(0)" onclick="record(<?=$val[TID]?>)"><?php echo $i . "、";?><?=$val[csa_text]?> <?=$val[TID]?></a>
</td>
</tr>
<?php
$i+=1;} ?>
</table>
onclick="record(<?=$val[TID]?>)这个跳转还是不行 <?=$val[TID]?>已经读取到数值了
这样写了<?php
$titles = array();
do {
array_push($titles,$row_Recordset_task);
#$row_Recordset_task获取数据库值,已定义
}while($row_Recordset_task = mysql_fetch_assoc($Recordset_task));?>
<table border="1" width="100%">
<?php $i=1;foreach($titles as $val){ ?>
<tr>
<td align="center">
<a href="javascript:void(0)" onclick="record(<?=$val[TID]?>)"><?php echo $i . "、";?><?=$val[csa_text]?> <?=$val[TID]?></a>
</td>
</tr>
<?php
$i+=1;} ?>
</table>
但是onclick还是不成功,ajax那些功能函数看不懂,不知道对不
function record(id){
alert("id-->>"+id); //这样有反应吗?
createXMLHttpRequest();
url = "action.php?id="+id+"&ran="+Math.random();
method = "GET";
xmlHttp.open(method,url,true);
xmlHttp.onreadystatechange = showList;
xmlHttp.send(null);
}
record的参数不是数字,需要加引号:<a href="javascript:void(0)" onclick="record('<?=$val[TID]?>')">html中<div id="show"></div>不能少,不然接收不到返回信息。
另,楼主添加action.php页面了吗?
print_r($rows);有结果吗?