数据库名为db_online,数据表名为tb_user,,数据表字段为online_id,online_user,online_number,online_pass,检索条件为以字段online_number,online_pass,PHP页面为chaxun.php。本人是新手,不要说太专业。求详细的代码和注释。因为急需,本人在线等。
ä¸é¢è¾åºä¸ä¸ªè¡¨æ ¼ï¼ä¸¤ä¸ªè¾å ¥æ¡ï¼è¾å ¥ç¨æ·å·åå¯ç ï¼
<form id="form1" name="form1" method="post" action="chaxun.php">
<table width="344" height="136" border="0" align="center" cellpadding="2" cellspacing="2">
<td width="100" height="35" align="right">ç¨æ·å·ï¼</td>
<td width="275"><input type="text" name="online_number" id="online_number" width="150" /></td>
</tr>
<tr>
<td align="right">å¯ç ï¼</td>
<td height="35"><input type="password" name="online_pass" id="online_pass" width="150" /></td>
</tr>
<tr>
<td height="45" colspan="2" align="center"><input type="submit" value="注å" /> </td>
</tr>
</table>
</form>
<?php
//ä¸é¢ç¼åå¤ç代ç ï¼æ说æ
header('Content-type:text/html;charset=utf-8');//设置ç¼ç æ ¼å¼ä¸ºutf8
if(isset($_POST['online_number']) && isset($_POST['online_pass']))
{
$db = new mysqli('localhost','test','test','db_online');//建ç«æ°æ®åºè¿æ¥ï¼ç¨æ·åãå¯ç ãæ°æ®åºæ ¹æ®å®é ä¿®æ¹
$pass = $_POST['online_pass'];
$num = $_POST['online_number'];
$rows = $db->query("SELECT * FROM tb_user WHERE online_number = $num AND online_pass ='$pass'");
$r_num = $rows->num_rows;
if($r_num>0)
{
echo '<table border="1"><tr>';
$row = $rows->fetch_row();
for($i=0;$i<count($row);$i++)
{
echo '<td>'.$row[$i].'</td>';
}
echo '</tr>';
} else
echo '<script>alert("ç¨æ·å·æå¯ç é误");</script>';
}
?>
å°ä»¥ä¸ä»£ç ä¿å为chaxun.phpï¼ä¿®æ¹ä½ å®é çæ°æ®åºè¿æ¥ãç¨æ·ååå¯ç ï¼è¿è¡è¿½é®
if(mysql_num_rows($sql)){
while($row = mysql_fetch_array($sql)){
echo $row["online_id"."online_user"."online_number"."online_pass];
}
}
else{
echo "ææ è®°å½";
}
mysql_free_result($sql);
?>
ä¸ç¥éè¿æ ·è¡ä¸è¡å¢ï¼
ä¸éè¦ç¨whileç»æå§ï¼å 为ä»é»è¾ä¸çï¼online_number + online_passãå¾å°çç»æåºè¯¥æ¯å¯ä¸çæ对ã
æ以ï¼ç¨
ãã$r_num = $rows->num_rows;
if($r_num>0)
è¿æ ·å¤æç»ææ¯ä¸æ¯å¤§äºé¶å°±å¯ä»¥äºã
æç¼åç代ç æ¯ç¨å¯¹è±¡ï¼ä½ ç¨çæ®éçè¿ç¨å½æ°ä¹å¯ä»¥ï¼ç»ææ¯ä¸æ ·çã
数据库会连,就是对具体显示数据表的内容不知道怎么下手。对PHP语言还不是很懂。
追答会连数据库就简单了,
写条sql语句再循环输出就可以了,给你来个简单的例子。
$sql = mysql_query("select * from 表名 where 条件 order by 排序字段 asc或desc",$conn);
if(mysql_num_rows($sql)){
while($row = mysql_fetch_array($sql)){
echo $row[字段名];//多个字段就用“.”连接起来输出。自己组合着用。
}
}else{
echo "暂无记录";
}
mysql_free_result($sql);
<?php
include("conn/query.php");
$online_number=$_POST['online_number'];
$online_pass=$_POST['online_pass'];
$sql = mysql_query("select * from tb_user where online_number='$online_number' and online_pass='$online_pass' order by online_id,online_user,online_number,online_pass from tb_user ORDER BY online_id",$link);
include("conn/query.php");
$online_number=$_POST['online_number'];
$online_pass=$_POST['online_pass'];
$sql = mysql_query("select * from tb_user where online_number='$online_number' and online_pass='$online_pass' order by online_id,online_user,online_number,online_pass",$link);