I am very new in php and I really try a few days to find a solution, I feel like I am almost there but still no success. I f someone can hep me I will be very happy. I am building a new website for prediction of football. I have a table in mysql and I can get successfully all rows which I need. I thing also I am storing the data also in a good way in an array.
this is the first php where I get the rows and stored them in an array, I also need columns data because I need them in the second php for the new query.
file name filtre1_danimarka.php
<?php
include 'tableNameDanimarka.php';
include 'indexDanimarka.php';
include 'connectionDatabase.php';
$sql = "SELECT *
FROM $tableName
where NOT A ='*' ";
$result = $conn->query($sql);
$array = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
for($i = 0, $j = count($array); $i < $j ; $i++){
$B= $array[$i]['B'];
$F = $array[$i]['F'];
$E = $array[$i]['E'];
$O = $array[$i]['O'];
$Home = $array[$i]['HOME'];
$Away = $array[$i]['AWAY'];
}
} else {
echo "0 results";
}
$conn->close();
?>
second php file Firsthalfprediction.php
<?php
include 'filtre1_danimarka.php';
include 'tableNameDanimarka.php';
include 'connectionDatabase.php';
$FirstHalfHome=0;
$FirstHalfDraw=0;
$FirstHalfAway=0;
$sql = "SELECT * FROM $tableName where B = '$B' AND E = '$E' AND F = '$F' AND O ='$O' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$rowcount=mysqli_num_rows($result);
// output data of each row
while($row = $result->fetch_assoc()) {
if($row['Q'] == 1){
$FirstHalfHome++;
}
elseif($row['Q'] == 0){
$FirstHalfDraw++;
}else{
$FirstHalfAway++;
}
}
$FirstHalfHomePrediction = round(($FirstHalfHome/$rowcount )*100);
$FirstHalfDrawPrediction = round(($FirstHalfDraw/$rowcount )*100);
$FirstHalfAwayPrediction = round(($FirstHalfAway/$rowcount )*100);
} else {
echo "0 results";
}
$conn->close();
?>
And the final index.php
<table class="table">
<thead>
<tr>
<th>Home</th>
<th>Away</th>
<th>FirstHalf Prediction</th>
</tr>
</thead>
<tr>
<?php
include 'filtre1_danimarka.php';
include 'Firsthalfprediction.php';
echo"<td>".$Home."</td>";
echo"<td>".$Away."</td>";
echo"<td>1=".$FirstHalfHomePrediction." 0=".$FirstHalfDrawPrediction."\r 2=".$FirstHalfAwayPrediction."</td>";
echo "</tr>";
?>
</table>
If I run the code like this, I am only getting the information from the last index in an array. What I need is all array data showing on the site. I hoop it was clear to understand my question. I hoop to get feedback thank's a lot.