Jump to content

StuHannah

Members
  • Posts

    14
  • Joined

  • Last visited

StuHannah's Achievements

Member

Member (2/5)

0

Reputation

  1. StuHannah

    Loop

    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
  2. Thank you both for your replies, definetly on the right track now. Stuart
  3. Sorry about that, I'll try and make it clearer now. So basically, we have several minibus' we use and staff book them out using a diary, very old school. I want to replace this now. We plan to split the timing into slots, so we could have around 8 slots that we can book the minibus’ out to. There will be a table called 'tbl_vehicles' VehicleID VehicleReg VehicleCapacity The next table will be the list of static bookings that are updated annually, I can manually do these as it’s typically specific times, such as Friday Afternoon, Tuesday Morning. This table will be named ‘tbl_static’ ID Day Slot Name VehicleID The plan would be that before the system is used I would pre-populate any static bookings into the backed and then from the client end these would be greyed out and not be able to book them. The next table would be ‘tbl_bookings’ which would be similar to the tbl_static except this will contain the bookings that have been made and we can then run reports on that table. Hope that makes sense now, and I hope this is achievable, don’t worry I am not seeking the full answer, just hoping what I want to work on makes sense. Stuart
  4. Hi All, I am starting to look at building a web based allocation to allow staff to book out our Minibus'. The easy part I have achieved, I have a list of the minibus' on the page in a table on the left hand side for staff to be able to see what we have, but the next bit is that I have to set it up in such a way where there are 8 sessions available for this to be booked, so I have been able to do this and loop through the database results to get what I am after. The problem I am facing now is that we have some permanent bookings that need to the made to the system, I was thinking of having a table with the session number and details about the booking and then my normal tables which hold the bookings. The part I am stuck at is, how can I take data from the static table and populate it before then allowing staff to be able to book it. Hope that all makes sense. S.
  5. Hi Everyone, I am looking for some help with creating a loop in PHP. Basically my table has columns named Mon1, Mon2, Mon3 all the way up to 50. I have pasted my code below, but I don't think it's a good way I am doing it. I have thought about trying to use the code (below the old code) <?php $result = mysqli_query($mysqli, $query); //while ($row = mysqli_fetch_array($result)) { // echo $row[0] . ': ' . $row[1] . ' ' . $row[2]; // echo '<br />'; //} while ($row = mysqli_fetch_array($result)) { echo $row['MON1'] . ' - ' . $row['MON2'] . ' - ' . $row['MON3'] . ' - ' . $row['MON4'] . ' - ' . $row['MON5']; echo '<br />'; echo $row['TUE1'] . ' - ' . $row['TUE2'] . ' - ' . $row['TUE3'] . ' - ' . $row['TUE4'] . ' - ' . $row['TUE5']; echo '<br />'; echo $row['WED1'] . ' - ' . $row['WED2'] . ' - ' . $row['WED3'] . ' - ' . $row['WED4'] . ' - ' . $row['WED5']; echo '<br />'; echo $row['THU1'] . ' - ' . $row['THU2'] . ' - ' . $row['THU3'] . ' - ' . $row['THU4'] . ' - ' . $row['THU5']; echo '<br />'; echo $row['FRI1'] . ' - ' . $row['FRI2'] . ' - ' . $row['FRI3'] . ' - ' . $row['FRI4'] . ' - ' . $row['FRI5']; echo '<br />'; } mysqli_free_result($result); mysqli_close($mysqli); ?> <?php $result = mysqli_query($mysqli, $query); $i = 1; while ($1 < 50) { while ($row = mysqli_fetch_array($result)) { echo $row['MON$i']; } } mysqli_free_result($result); mysqli_close($mysqli); ?> Kind Regards, Stuart
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.