是这样,我某一个页面上要显示一个角色对应的四个父亲名(最多也只能是四个)
html代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>旧的回忆F</title>
<link rel="stylesheet" type="text/css" href="../Public/css/old.css">
<style type="text/css">
body,td,th {
0;
font-size: 20px;
color: #673310;
font-family:"楷体";
}
</style></head>
<body>
<div id="containt">
<div id="backa">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="backb">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="backc">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="backd">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="work">
<a href=""><img src="../Public/img/mapimg/button/return.gif" /></a>
</div>
</div>
</body>
</html>数据库中存放该信息的表名叫father,里面有两个字段(user_name,fname)
html代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>旧的回忆F</title>
<link rel="stylesheet" type="text/css" href="../Public/css/old.css">
<style type="text/css">
body,td,th {
0;
font-size: 20px;
color: #673310;
font-family:"楷体";
}
</style></head>
<body>
<div id="containt">
<div id="backa">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="backb">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="backc">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="backd">
<table align="center" border="0">
<tr><td>父亲:</td></tr>
</table>
</div>
<div id="work">
<a href=""><img src="../Public/img/mapimg/button/return.gif" /></a>
</div>
</div>
</body>
</html>数据库中存放该信息的表名叫father,里面有两个字段(user_name,fname)
嗯,我是用了循环显示了它,它现在也可以显示出来,不过位置都不对了。
<?php
include "conn.php";
session_start();//启动session
$sql="select * from father ";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
$id=1;
?>
<div id=<?=$id?>>
<table align="center" border="0">
<tr><td>父亲:<?=$row[fname]?></td></tr> </table>
</div>
<?php
$id = $id+1;}
?>
我在css里定义了1,2,3,4四个div的位置,我觉得可能是我div的id那个地方用法有不对吧
while($row=mysql_fetch_array($query)){
貌似还是不行还有个问题就是在easy-eclipse里还可以显示父亲名,但是用浏览器的话就完全显示不出来了
好像是有点不太一样,但是我也不知道是正确还是不正确啊
它现在变成这样子了
<!--?php
include "conn.php";
session_start();//启动session
$sql="select fname from father ";
$query=mysql_query($sql);
$id=1;
while($row=mysql_fetch_array($query)){ ?-->
<div id="<?=$id?">>
<table align="center" border="0">
<tbody><tr><td>父亲:<!--?=$row[fname]?--></td></tr> </tbody></table>
</div>
<!--?php
$id = $id+1;}
?-->
将形如 <?=$row[fname]?> 改为 <?php echo $row[fname]?> 或者就开启段标签功能。
可是我之前没在html中加上这段代码前,css定位是对的呀~~~之后我的css就木有改过啊
还有一个问题就是刚才我查了下,说div必须要字母开头,所以好像我这么做是不可以的这个要怎么办?
还有个问题,我现在显示出来的父亲名,在后面我还想用。
就是,这个页面显示出父亲名了吧,然后这个父亲我给做了个连接,连接到下一个php页面中 了,在下一个php页面里我又想获取这个父亲名怎么办?
<a href='next.php?id=<?php echo $row[id]?>'><?php echo $row[fname]?></a>
每太看懂你的意思呀(某娃子表示自己很菜啊)我是这么想的,想把它作为全局变量
<tr><td><a href="old_memoryD.php">父亲:<?=$row[fname]?></a></td></tr>
<?php
$father_name=$row[fname];
$_SESSION['fname']=$father_name;//把fname定义为全局变量
?>这么写行么?然后下一个php页面我直接这样用:
$father_name=$_SESSION['fname']; //接收父亲名不过好像是没过来我也不知道是什么问题了
session_start();已经开启了呀,可是貌似好像还是读不到
放在哪个的开头?整个页面的开头还是
<?php
$father_name=$row[fname];
$_SESSION['fname']=$father_name;//把fname定义为全局变量
?>
的前头?我试了下两边都放还是收不到
而且我试了一下,在当前页面,echo $_SESSION['fname'];
是可以输出正确的值的,但是我在一下个页面引用的之后再输出就变成了???
其实我觉得我现在的问题好像是把所有的父亲名都传成全局变量了,实际上应该是我点击哪个就把哪个父亲名传成全局变量。
现在是这样的:
<table align="center" border="0">
<tr><td><a href="old_memoryD.php">父亲:<?=$row[fname]?></a></td></tr>
<?
session_start();
$_SESSION['fname']=$row[fname];
?>
$sql="select * from father where id= $id";
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
print_r($row);
它报了一个Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
在$row=mysql_fetch_array($query); 这一行
$query=mysql_query($sql) or die(mysql_error()); //这样看看
传id的时候我是这么写的
<a href='old_memoryD.php' id=<?php echo $row[id]?>>父亲:<?=$row[fname]?>
报错了
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
现在它报了一个Unknown column 'id' in 'where clause'
我用不用使用个form表单传输数据?