Php 从文本字段向表中添加值
有一个文本字段和一个表。如果我们在该文本字段中输入一个值,则需要在数据库的表上显示相应的名称:Php 从文本字段向表中添加值,php,mysql,arrays,html-table,textfield,Php,Mysql,Arrays,Html Table,Textfield,有一个文本字段和一个表。如果我们在该文本字段中输入一个值,则需要在数据库的表上显示相应的名称: <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <center><table> <tr><td>no</td><td><input type="text" name="no" autofocus></td>&
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<center><table>
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr>
</table></center>
<br>
<br>
<center>
<table cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
<thead>
<tr>
<th> Element_Number</th>
</tr>
</thead>
<?php
if(isset($_POST['no']))
{
$c=mysql_connect("localhost","root","");
mysql_select_db("test");
if(!$c)
{
echo "db prob".mysql_error();
}
$no=$_POST['no'];
$qry=mysql_query("select name from opt where no='$no'");
if(!$qry)
{
echo "ret".mysql_error();
}
if(mysql_num_rows($qry)!=0)
{
$row=mysql_fetch_array($qry);
$name=$row['name'];
}
else
{
echo "query Invalid";
}
echo "<td>" .$name."</td></tr>" ;
}
?>
我想做什么来获得这样的输出--->
您需要一个while查询来获取所有结果,而不仅仅是第一个结果代码>
no--001
|element no |
| aaa |
no--002
|element no |
| bbb |
no--001
|element no |
| aaa |
no--002
|element no |
| aaa |
| bbb |
no--003
|element no |
| aaa |
| bbb |
| ccc |