
初学者写的,你可以试试
<form name="myform" method="post" action="mysql.php"><table border="1">
<tr>
<td width="605" height="51" bgcolor="#CC99FF" colspan="2">
<div align="center">请输入用户名称
<input name="txt_user" type="text" id="txt_user" size="25">&nbsp
<input type="submit" name="Submit" value="查询">
</div>
</td>
</tr>
<tr>
<td align='center'>用户名称</td>
<td align='center'>年龄</td>
</tr>
<?php
// mysql_connect(服务器,用户名,密码)
$link = mysql_connect("localhost","root","root")
// mysql_select_db(数据库,$link)
$db_selected = mysql_select_db("php_test",$link)
// 编码格式(貌似很重要)
mysql_query("set names 'utf8'")
?>
<?php
$sql = mysql_query("select name_,age_ from t_user")
$info = mysql_fetch_array($sql)
if($_POST[Submit]=="查询"){
$txt_user = $_POST[txt_user]
$sql = mysql_query("select * from t_user where name_ like '%".trim($txt_user)."%'")
$info = mysql_fetch_array($sql)
}
?>
<?php
if($info==false){
echo '<tr><td width="605" height="51" bgcolor="#CC99FF" colspan="2">'
echo "<div align='center' style='color:#FF0000font-size:12px'>对不起,您查找的用户信息不存在!</div>"
echo '</td></tr>'
}elseif($info){
echo 'elseif'
}
?>
<?php
do{
?>
<tr align="center" bgcolor="#FFFFFF">
<td height="20"align="center"> <?php echo $info['NAME_']?></td>
<td> <?php echo $info['AGE_']?></td>
</tr>
<?php
}while($info = mysql_fetch_array($sql))
mysql_free_result($sql)
mysql_close($link)
?>
</table>
</form>
主要的写出来啊$query="select
*
from
student
where
id=01"
$res=my_sql_query($query)
$date=array()//保存得到的数据
where($row=mysql_fetch_assoc($res)){
$date=$row['填写你表的字段']
}
下面循环遍历$date输出到table就可以了啊
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)