select * from tableA
输出时
while($row=mysql_query(...))
{
再搜索另一个表,寻找对应的子记录
select * from tableB where Class_id='$row[Class_id]'
最后输出
while($row2=mysql_query(...))
{}
}两张表以Class_id字段做为关联,即先在tableA取出一条记录,取得其Class_id字段的值。然后到到tableB搜索Class_id相同的记录,再输出。
输出时
while($row=mysql_query(...))
{
再搜索另一个表,寻找对应的子记录
select * from tableB where Class_id='$row[Class_id]'
最后输出
while($row2=mysql_query(...))
{}
}两张表以Class_id字段做为关联,即先在tableA取出一条记录,取得其Class_id字段的值。然后到到tableB搜索Class_id相同的记录,再输出。
<?
$query=mysql_query('select * from type') or die ($rs_err); //打开系统基本设置数据表type;
while($array=mysql_fetch_array($query)){
?>
<table width="549" border="0" cellpadding="0" cellspacing="0" background="images/class.gif">
<!--DWLayoutTable-->
<tr>
<td width="549" height="20" ><font color="ffffff">
<li><? echo $array["typename"];?>
</li>
</font>
<a href="class.php?id=<? echo $array["type_id"];?>"><font color="ffffff">more</font></a></td>
</tr>
</table>
<!------------文章开始------------>
<?
$article_type=$array["type_id"];
$query2=mysql_query("select * from article where type='$article_type' order by article_id desc limit 0,5") or die ($rs_err); //打开系统基本设置数据表article;
while($array2=mysql_fetch_array($query2)){
?>
<table width="550" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="550" height="22" valign="middle"><table width="100%" border="0">
<tr>
<td width="65%"><a href="article.php?class=<? echo $array["type_id"]?>&id=<? echo $array2["article_id"];?>" target="_blank"><? echo $array2["title"];?></a></td>
<td width="35%"><? echo $array2["date"];?></td>
</tr>
</table></td>
</tr>
</table> <? }?>
<!------------文章结束------------>
<? }?>
用两个,如下:
while (){ //表A并显示记录
while() {
//打开表B,并显示记录}}
源代码如下:
-------------------------------------------------------------------------------
<?php require_once('../Connections/conn.php'); //这里是链接到数据库的 ?>
<?php
mysql_select_db($database_conn, $conn);
$query_c1 = "SELECT * FROM a";
$c1 = mysql_query($query_c1, $conn) or die(mysql_error());
$row_c1 = mysql_fetch_assoc($c1);
$totalRows_c1 = mysql_num_rows($c1);
?>
<html>
<head>
<title>Untitled Document</title>
<script>// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
var p, i, foundObj;
if(!theDoc) theDoc = document;
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
{
theDoc = parent.frames[theObj.substring(p+1)].document;
theObj = theObj.substring(0,p);
}
if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
for (i=0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];
for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj,theDoc.layers[i].document);
if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
return foundObj;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.u {
padding-left: 20px;
}
-->
</style>
</head><body>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr> <!--此处是关键-->
<td width="200" bgcolor="#E4E1CF" style="cursor:hand" onMouseUp="with(findObj('<?PHP echo "C01".$row_c1['class_id'];?>').style){display=display=='none'?'':'none';}"> + <?php echo $row_c1['class_name']; ?></td>
</tr>
<tr id="<?PHP echo "c01".$row_c1['class_id'];?>"><!--此处是关键-->
<td bgcolor="#F0EDE8" class="u"><?
$class_type=$row_c1["class_id"];
$query_c2 = "SELECT * FROM b where class_id='$class_type'";
$c2 = mysql_query($query_c2, $conn) or die(mysql_error());
$row_c2 = mysql_fetch_assoc($c2);
$totalRows_c2 = mysql_num_rows($c2);
do {
?>
<table width="180" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> - <?php echo $row_c2['b_name']; ?></td>
</tr>
</table><?php
} while($row_c2 = mysql_fetch_assoc($c2));
?></td>
</tr>
<?PHP
} while ($row_c1 = mysql_fetch_assoc($c1));
?>
</table>
</body>
</html>
<?php
mysql_free_result($c2);
mysql_free_result($c1);
?>
<td width="200" bgcolor="#E4E1CF" style="cursor:hand" onMouseUp="with(findObj('<?PHP echo "C01".$row_c1['class_id'];?>').style){display=display=='none'?'':'none';}"> + <?php echo $row_c1['class_name']; ?></td>
</tr>
<tr id="<?PHP echo "c01".$row_c1['class_id'];?>" style="display:none;"><!--此处是关键-->------------------------------------------------------
这样就可以显示大类了,再点加号就可以看到小类;
while($arr = mysql_fetch_array($query))
{
php 学习
php 源码
php 提问
jsp 学习
jsp 源码
jsp 提问这样的数据按你那个样式排列应该不难吧
}