从文本字段向表中添加值

时间:2014-06-01 05:31:31

标签: 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></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>" ;

}
?>

当我尝试这样的代码输出时 - &gt;

no--001

|element no     |

|   aaa         |


no--002

|element no     |

|   bbb         |

我想做什么来获得这样的输出---&gt;

no--001


|element no     |

|   aaa         |

no--002


|element no     |

|   aaa         |

|   bbb         |


 no--003

|element no     |

|   aaa         |

|   bbb         |

|   ccc         |

0 个答案:

没有答案