Hello im here with a problem, i want to retrieve data from mysql with php(done it :)) and then for example when my variable $dia_semana
is equal to sunday, it will show all the data with sunday into a especific div with a certain id, and then goes on
here is my php code:
<?php function dia_da_semana() { $connect = mysqli_connect("", "", "", ""); $sql ="SELECT temperature, humidity, data FROM sensor ORDER BY data DESC LIMIT 1"; $result = mysqli_query($connect, $sql); setlocale(LC_TIME, "pt_PT"); // or LC_TIME while($row = mysqli_fetch_array($result)) { echo strftime("%A",$row['data']); echo "<h2>".$row['data']."</h2>"; echo "<h4>".$row['temperature']."ÂșC</h4>"; echo "<h4>".$row['humidity']."%</h4>"; } } dia_da_semana(); ?>
part of html code where i want it to be sent:
<div class="7days"> <?php include "loadgraph.php" ?> <div class="day1"> </div> <div class="day2"> </div> </div>
Advertisement
Answer
this is my code that fully works:
$WEEKDAYS = array(1 => "Sunday", 2 => "Monday", 3 => "Tuesday", 4 => "Wednesday", 5 => "Thursday", 6 => "Friday", 7 => "Saturday"); $ResultsArray = array(); while($row = mysqli_fetch_array($result)) { // create an array to hold the return values from your DB $date = $row['dia_semana']; //<--- coming from db holds date values $ResultsArray[$date][] = $row['temperature']; } echo "<table style='padding:5px;border-radius: 10px;border:solid 1px #000;vertical-align: text-top;'>"; echo "<tr>"; foreach ($WEEKDAYS as $key => $date) { echo "<th>".$date."</th>"; } echo "</tr>"; for ($x = 0; $x < 1; $x++){ echo "<tr>"; echo "<td>".$ResultsArray['Sunday'][$x]."</td>"; echo "<td>".$ResultsArray['Monday'][$x]."</td>"; echo "<td>".$ResultsArray['Tuesday'][$x]."</td>"; echo "<td>".$ResultsArray['Wednesday'][$x]."</td>"; echo "<td>".$ResultsArray['Thursday'][$x]."</td>"; echo "<td>".$ResultsArray['Friday'][$x]."</td>"; echo "<td>".$ResultsArray['Saturday'][$x]."</td>"; echo "</tr>"; } echo "</table>";