我正在显示数据库中的记录表,但是当显示记录时,它会显示很多记录,我不知道为什么,但是我只需要一行,但它可能显示成千上万条记录。似乎有一个令人沮丧的行问题,我需要帮助。非常感谢你 .............................................. ..............
<?php
include("auth_admin.php");
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `lcho_dengue_activities` where `month`= '".$valueToSearch."' ";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `lcho_dengue_activities`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "lcho_login");
$filter_Result = mysqli_query($connect, $query);
if (!$filter_Result) {
printf("Error: %s\n", mysqli_error($connect));
exit();
}
return $filter_Result;
}
?>
<form action="filterdata.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<table>
<tr>
<th>Vaccine</th>
<th>San Francisco</th>
<th>San Celestino</th>
<th>Malitlit</th>
<th>Sto. Toribio</th>
<th>San Benito</th>
<th>Sto. Nino</th>
<th>San Isidro</th>
<th>Munting Pulo</th>
<th>Latag</th>
<th>Sabang</th>
<th>Tipacan</th>
<th>San Jose</th>
<th>Tangob</th>
<th>Antipolo del Norte</th>
<th>Antipolo del Sur</th>
<th>Pinagkawitan</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php
echo "boom";
?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '1' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num1 FROM lcho_childcare WHERE barangay_id= '2' ");
$indicator10='ind_num1'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num1'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '3' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '4' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '5' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '6' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '7' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '8' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '9' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '10' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '11' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '12' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '13' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '14' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '15' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
<td><?php mysql_connect("localhost","root",""); //phpmyadmin username and pass
mysql_select_db("lcho_login"); //your database name needs to access
$sql=mysql_query("SELECT sum(`ccare_ind1`) AS ind_num FROM lcho_childcare WHERE barangay_id= '16' ");
$indicator10='ind_num'; // name column in the table
while($row = mysql_fetch_array( $sql )) {
echo $row['ind_num'];
};?></td>
</tr>
<?php endwhile;?>
</table>
</form>