StuHannah Posted October 7, 2017 Share Posted October 7, 2017 Hi, I want to create a loop within PHP and MySQL. At the moment my table has a column named active that is either 0 or 1 to represent active or not. I want to update my current loop. I know that there are 5 days we operate (at the moment) so I want to pull through the table using a variable so that I can loop through and select days that are active and for the days that are not active simply print a greyed out row. Can anyone point me in the right direction, I was thinking a whileloop so for example: // $i is the days we are active) while ($i = 1, $i <= 5, $i++) { echo "Day name"; // If the day is active then print the name } else if the day isn't active it will still be printed, but greyyed out. This is my current query: $query = "SELECT * FROM tbl_days WHERE Active = 1"; $result = mysqli_query($dblink, $query);if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "<tr>"; echo "<td>" . $row["ID"] ."</td>"; echo "<td>" . $row["DayName"] . "</td>"; echo "<td>" . $row["Active"]. "</td>"; echo "</tr>"; } } else { echo "Nothing active on the system at the moment."; } Thanks in advance, and hope i've given enough information. S Quote Link to comment Share on other sites More sharing options...
requinix Posted October 7, 2017 Share Posted October 7, 2017 If you want to show active and inactive days then your query needs to return all of them, not just the active ones. Then loop. A while is fine for it. If the day is active then do one thing, otherwise the day is inactive so do a different thing. Beyond that it depends on what output you need to create, so if you don't know that then figure it out first. Like with some test data that doesn't come from the database. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.