1
此处的问题是所有值都不会打印在表格中。我收到数据库中的所有信息,表中只打印一行,其他值打印在下面。对于,当我搜索名称“亚历克斯”时,我有更多的价值与相同的名称在数据库中,我得到他们所有,但只有一个值被打印在表中。while循环仅在表格中打印一行其他行在下面不打印在表格中
<div id="search">
<form method="get" action="search_display.php" id="searchform">
<h1> Search </h1>
<input type="text" name="query" />
<input type="submit" value="Traži" />
</div>
//search_display.php file
<?php
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length){
$sql_result = mysql_query("SELECT *
FROM clanovi
WHERE (`IME` LIKE '$query')
OR (`PREZIME` LIKE '$query ')
OR (`FIRMA` LIKE '$query')") or die(mysql_error());
if(mysql_num_rows($sql_result) > 0){
echo "<table border='5'>
<tr>
<th>IME</th>
<th>PREZIME</th>
<th>FIRMA</th>
<th>ADRESA</th>
<th>TELEFON</th>
<th>FAX</th>
<th>MOBITEL</th>
<th>EMAIL </th>
<th>WEB_STRANICA </th>
<th>GRAD </th>
<th>KATEGORIJA </th>
<th>PROIZVODI </th>
</tr>";
while($row = mysql_fetch_array($sql_result)){
{
echo "<tr>";
echo "<td>" . $row ['IME'] . "</td>";
echo "<td>" . $row ['PREZIME'] . "</td>";
echo "<td>" . $row ['FIRMA'] . "</td>";
echo "<td>" . $row ['ADRESA'] . "</td>";
echo "<td>" . $row ['TELEFON'] . "</td>";
echo "<td>" . $row ['FAX'] . "</td>";
echo "<td>" . $row ['MOBITEL'] . "</td>";
echo "<td>" . $row ['EMAIL'] . "</td>";
echo "<td>" . $row ['WEB_STRANICA'] . "</td>";
echo "<td>" . $row ['GRAD'] . "</td>";
echo "<td>" . $row ['KATEGORIJA'] . "</td>";
echo "<td>" . $row ['PROIZVODI'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
}
else{ // if there is no matching rows do following
echo "Vaš unos ne postoji u bazi podataka!";
}
}
else{ // if query length is less than minimum
echo "Minimalna dužina je ".$min_length. "slova";
}
?>
尝试通过它来查询,并保持该mysql_ *功能已被弃用的说明之前验证用户输入。 –
我建议你使用一些好的IDE.SO东西像Netbeans(必须安装jdk)。并编写代码时,你正在写它.Pozdravi ot瓦尔纳;) –