启用 - 禁用表结果

时间:2013-07-22 07:05:24

标签: php html

我正在为我的学校项目制作一个电话簿,但到目前为止这是我的工作。我想隐藏表头(姓氏,名字等)  在得到结果后查看它。 Before Search. Header is view(I want to hide it)

After Search. I want to view the header

此图像位于我搜索名称之前和之后 这是我的代码:

    <table class="gridtable">
    <th>Last Name</th>
    <th>First Name</th>
    <th>Address</th>
    <th>Telephone Number</th>
    <th>Network</th>
    <th>Something Wrong?</th>

这是我的表格标题

include 'database.php';

$lname = "";
$fname = "";

if(isset($_POST['lname'])  || (isset($_POST['fname']))){ $fname = $_POST['fname'];     $lname = $_POST['lname']; }

if(!isset($_POST['fname']) || ($_POST['lname'])) ;

$vars = array('lname');
$verified = TRUE;
foreach($vars as $v) {
if(!isset($_POST[$v]) || empty($_POST[$v])) {
  $verified = FALSE;
}
}
if(!$verified) {
exit();
}


$result = mysql_query("SELECT * FROM sheet1 WHERE lname like '%$lname%' AND fname like     '%$fname%' ");

这是我回应结果的地方

if($count = mysql_num_rows($result)){


echo "<p class=\"count\"> <b>$count </b> Results  for <b><i>\" $lname $fname \"</i></b>   </p>";
}
else 
echo "<p class=\"count\"> No Result for - <b><i>\" $lname $fname  \"</i></b></p>";

while(@$row = mysql_fetch_array($result)){
echo

"<tr>" .
"<td><b>" . $row['lname'] . "</b></td>" .
"<td><b>" . $row['fname'] . "</td>" .
"<td>" . $row['address'] . "</td>" .
"<td>" . $row['telnum'] . "</td>" .
"<td>" . $row['network'] . "</td>" .
"<td>" . 
"<input type = \"submit\" value= \"Report\" class= \"classname \" name= \"report\">" . 
"</tr>";



}
?>

1 个答案:

答案 0 :(得分:1)

您需要将表格置于

状态
if(mysql_num_rows($result) > 0) { //Process if SQL returns more than 0 rows
   //Table code here
}
  

警告:您正在使用已弃用的mysql_(),请考虑使用   mysqli_()或PDO。