问题
我想知道在连接或搜索数据库时如何使屏幕顶部的文本不显示。下面是我正在谈论的截图。
它有可能根本不出现吗?下面是连接到数据库的代码,以及下面表单的代码。
代码
连接数据库的代码:
<?php
// Connecting, selecting database
$dbconn = pg_connect("host=***** port=*****
dbname=***** user=***** password=*****")
or die('Could not connect: ' . pg_last_error());
//collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
// $searchq = preg_replace("#[^0-9a-z]#i"."".$searchq);
// Performing SQL query
$query = "SELECT vegan FROM enumbers WHERE code LIKE '%$searchq%'";
$ret = pg_query($dbconn, $query);
if(!$ret){
echo pg_last_error($dbconn);
exit;
}
$output = '';
while($row = pg_fetch_assoc($ret)){
$code = $row['code'];
print_r($row);
$name = $row['name'];
$type = $row['type'];
$vegan = $row['vegan'];
$output .= '<div> '.vegan.' ';
}
}
echo "Operation done successfully\n";
pg_close($dbconn);
?>
表单的代码:
<div id="tablebox">
<!-- Search bar -->
<p>Is It Vegan?</p>
<form name="form1" method="post" action="searchEnumbers.php">
<input name="search" type="text" size="30" maxlength="5" />
<input name="submit" type="submit" value="Search" />
</form>
<?php
print("$output");
?>
</div>
</div>
答案 0 :(得分:3)
只需从代码中删除这两行
即可print_r($row);
.....
echo "Operation done successfully\n";
答案 1 :(得分:1)
试试这个,通过 php comment(//)
注意更改<?php
// Connecting, selecting database
$dbconn = pg_connect("host=***** port=*****
dbname=***** user=***** password=*****")
or die('Could not connect: ' . pg_last_error());
//collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
// $searchq = preg_replace("#[^0-9a-z]#i"."".$searchq);
// Performing SQL query
$query = "SELECT vegan FROM enumbers WHERE code LIKE '%$searchq%'";
$ret = pg_query($dbconn, $query);
if(!$ret){
echo pg_last_error($dbconn);
exit;
}
$output = '';
while($row = pg_fetch_assoc($ret)){
$code = $row['code'];
//Commented 1
//print_r($row);
$name = $row['name'];
$type = $row['type'];
$vegan = $row['vegan'];
$output .= '<div> '.vegan.' ';
}
}
//Commented 2
//echo "Operation done successfully\n";
pg_close($dbconn);
?>