2
Answers

Display a first record of two different columns on two separate inputs

Hi Sirs,

The code I wrote are fine. But I cannot display records after filter. The what I need it's simple. I have two separate records on top of my form or outside of my form. After the interval of year be filtered I would love to see the first record be displayed on those separated inputs (girls on input1 and boys on input2). Any filter I do the first record should be displayed separetly. Thank you!

<html lang="en" class="notranslate" translate="no">

<head><meta name="google" content="notranslate" />

</head>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<style>

body {

background-color: #fff4e6;

}

table,th,td

{

border:1px solid white;

color:#1d3557;

}

table

{

border-collapse:collapse;

width:80%;

}

th

{

background-color: PaleVioletRed;

}

td

{

height:30px;

}

td:nth-child(1)

{

background-color: #a9bcd0;

}

td:nth-child(2)

{

background-color: #a9bcd0;

}

td:nth-child(3)

{

background-color: #a9bcd0;

}

td:nth-child(4)

{

background-color: #a9bcd0;

}

td:nth-child(5)

{

background-color: #a9bcd0;

}

td:nth-child(6)

{

background-color: #a9bcd0;

}

td:nth-child(7)

{

background-color: #a9bcd0;

}

td:nth-child(8)

{

background-color: #a9bcd0;

}

td:nth-child(9)

{

background-color: #a9bcd0;

}

td:nth-child(10)

{

background-color: #a9bcd0;

}

</style>

</head>

<style>

.button7 {

background-color: Brown;

color: white;

border-radius: 15px 50px 30px;

border: 0px solid #008CBA;

font-size: 30px;

width: 380px;

height: 50px;

text-align: left;

padding: 0px;

text-align: center;

}

.button7:hover {

background-color: #e7e7e7;

color: black;

}

</style>

<style>

.recherche {

background-color: MediumSlateBlue;

color: white;

border-radius: 25px;

border: 0px solid #008CBA;

font-size: 30px;

width: 120px;

height: 50px;

text-align: left;

padding: 0px;

text-align: center;

}

.recherche:hover {

background-color: #e7e7e7;

color: black;

}

</style>

<!--script>

function myFunction() {

}

setInterval(function(){

document.getElementById("recherche").click();

}, 10000);</script-->

<?php

if(isset($_POST['recherche']))

{

include('testdb.php');

$valueToSearch = $_POST['valueToSearch'];

// search in all table columns on a specific column

$query = "SELECT * FROM statflex_info WHERE year = '$valueToSearch'";

$search_result = filterTable($query);

}

else {

$query = "SELECT * FROM statflex_info ORDER BY id DESC LIMIT 10";

}

// function to connect and execute the query

function filterTable($query)

{

$connect = mysqli_connect("x","xx","xxx","xxxx");

$filter_Result = mysqli_query($connect, $query);

return $filter_Result;

}

?>

<!DOCTYPE html>

<html>

<head>

<title>Recherche</title>

<h1 style="color: MediumVioletRed">. Effectifs numériques total d'Elèves .</h1>

<hr>

<style>

table,tr,th,td,td1

{

border: 1px solid white;

}

</style>

</head>

<body>

<br>

</br>

<br>

<!--the problem is HERE please-->

<table>

<th><input type="text" name="girls" id="girls" value="<?= $row['girls']; ?>"></th>

<th><input type="text" name="boys" id="boys" value="<?= $row['boys']; ?>" ></th>

</table>

<center><form action="268_" method="post">

&nbsp;<label style="font-size:35px;font-weight:normal;">Search/year:</label>

<select name="valueToSearch" id="valueToSearch" style="font-size:35px;font-weight:normal;width:8em;border-radius: 15px;">

<option value="Selectionner">Select</option>

<option value="2025/2026">2025/2026</option>

<option value="2026/2027">2026/2027</option>

<option value="2027/2028">2027/2028</option>

<option value="2028/2029">2028/2029</option>

<option value="2029/2030">2029/2030</option>

</select>

&nbsp;<input type="submit" name="search" id="search" class="search" value="Filter">

</form></center>

<br>

<br>

<center><table style="white-space:nowrap;width:70%;">

<tr>

<th style="font-size:25px;color:white;font-family: Arial">code_city</th>

<th style="font-size:25px;color:white;font-family: Arial">girls</th>

<th style="font-size:25px;color:white;font-family: Arial">boys</th>

<th style="font-size:25px;color:Navy;font-family: Arial">total</th>

</tr>

<?php

// $total_price = 0;

while($row = mysqli_fetch_array($search_result))

{

echo "<tr>";

echo "<td align=center style='font-size:25px'>" . $row['code_city'] . "</td>";

echo "<td align=center style='font-size:25px'>" . $row['girls_number'] . "</td>";

echo "<td align=center style='font-size:25px'>" . $row['boys_number'] . "</td>";

echo "</tr>";

// add the price to the total

$total_girls += $row['sexe_girls_number'];

$total_boys += $row['sexe_boys_number'];

$total = ($total_girls + $total_boys);

}

// add a last row to display only the total price in the last column

echo "<tr><th></th><th align=center style='font-size:25px;color:white'>$total_girls</th><th align=center style='font-size:25px;color:white'>$total_boys</th>

<th align=center style='font-size:25px;color:Navy'>$total</th>

<tr>";

// closeing table tag

echo "</table></center>";

mysqli_close($con);

?>

</form>

</body>

</html>

Answers (2)