Jump to content

StuHannah

Members
  • Content Count

    14
  • Joined

  • Last visited

Community Reputation

0 Neutral

About StuHannah

  • Rank
    Member
  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. SIMS.net is a School Information Management System, not the game. The site is nothing to do with me. I was simply looking at a way of developing my own internal booking system, taking away the need to use paper, and without costing anything but my time. All I was doing was trying to learn along the way. Thanks anyway and best wishes. Stuart
  6. This table contains all of the MIS Data from SIMS.net. The report that runs grabs the following information: Room Name Period Class name Staff Code Room1 MonA:1 7L/IT1 ASm Room1 MonA:2 8R/Ma1 PKa CREATE TABLE `tbl_misdata` ( `MIS_ID` int(11) NOT NULL, `MIS_Room` varchar(200) NOT NULL, `MIS_Period` varchar(200) NOT NULL, `MIS_Class` varchar(200) NOT NULL, `MIS_Staff` varchar(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; This table contains all the available periods available on the MIS System. (These are static so I’ve extracted them from the SIMS report) CREATE TABLE `tbl_periods` ( `Period_Name` varchar(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; This table contains the list of rooms. Again these are manually added to the DB. If we wanted a new room, I would add it to the system manually, and the edit the report to include this in the data export. CREATE TABLE `tbl_rooms` ( `RM_ID` int(11) NOT NULL, `RM_Name` varchar(100) NOT NULL, `RM_Desc` varchar(200) NOT NULL, `RM_Available` varchar(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; This table contains the list of rooms. Again these are manually added to the DB. If we wanted a new room, I would add it to the system manually, and the edit the report to include this in the data export. CREATE TABLE `tbl_weeks` ( `Week_ID` int(11) NOT NULL, `week_Name` varchar(100) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1; This table will eventually have the extra bookings that have been added by the end user. CREATE TABLE `tbl_bookings` ( `Booking_` int(11) NOT NULL, `Booking_Room` varchar(200) NOT NULL, `Booking_Period` varchar(200) NOT NULL, `Booking_Week` varchar(200) NOT NULL, `Booking_User` varchar(200) NOT NULL, `Booking_Class` varchar(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Brief overview of some of the pages Admin Side SetupWeeks.php – Loops through 52 weeks ahead of the week it has been opened (So gets used once a year) and has checkboxes with A/B/H as the options. A = Week A, B = Week B and H = Holiday. The idea with this is that when the main page loads, it will get the current week we are on; query the database to see what sort of week we are on, then pull that week’s MIS information. NewRoom.php – Creates a new room in the tbl_rooms table, where it is given details such as number of pc’s etc. End User Index.php – Page loads, connecting to the DB. Check what week we are on, starting at Monday. Once it has determined the week, it checks the database to see what week it is. If it is an A week, it will query filtering all the A week MIS information, if it’s a B Week, same again checks for the B week information. If the week is a H, it simply lets the user know it’s a holiday week. Bit I am up to! Once the MIS data has been brought to the end user, it will print the current information on the screen, however at present it will print everything, but if there is a gap i.e. there isn’t any MIS data available as the period is free, it doesn’t print that it’s free, as I know it doesn’t have the information, so it’ won’t know – There are always 5 sessions a day, so was thinking of having a variable with that states and for each result i.e. $i=5 for each monA:$i <5) print the result, if (!$result)then print to say it’s free. Hope this will help, and provide you with enough information. Apologies for not providing all information earlier, burning the candle at both ends at the moment.
  7. Yeah we run a two week cycle so have two lots of data, week a data and week b all in one table, the idea is that when the user loads up the page, it will determine what week it is and query the data only from that week. Hope that makes sense. Stuart
  8. The MIS is SIMS and I am unsure if there is an API, I'm simply pulling data through the command reported into a csv the have a script to import this to the MySQL mis data table.
  9. They mean the week and session. MONA:1 = Monday of Week A, session 1. MONB:1 = Monday of Week B, Session 1.
  10. Thanks for the reply. Just realised I didn't say MySQLi, was just Pseudo'ing it out off the top of my head as an idea. Below is the table structure: tbl_misdata is the data straight from the MIS system tbl_periods are all the periods we use i.e. MONA:1, MONA:2 (A being the week we are on and the number is the session) tbl_rooms the list of rooms we have to book. tbl_weeks list of weeks and wether they are A week, B week or a Holiday. So my Pseudo, to help explain it: In the admin side, we specify the weeks in the DB so they are A/B/H When the page loads, it checks what week we are on by date and then queries the DB to see what type of week this is. Once we determine week, we are able to loop through the misdata where it matches the week (so if we return an A week, we want all the data that matches MonA% in the query. Hope this helps! #readytotakeabeating CREATE TABLE `tbl_bookings` ( `Booking_` int(11) NOT NULL, `Booking_Room` varchar(200) NOT NULL, `Booking_Period` varchar(200) NOT NULL, `Booking_Week` varchar(200) NOT NULL, `Booking_User` varchar(200) NOT NULL, `Booking_Class` varchar(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `tbl_misdata` ( `MIS_ID` int(11) NOT NULL, `MIS_Room` varchar(200) NOT NULL, `MIS_Period` varchar(200) NOT NULL, `MIS_Class` varchar(200) NOT NULL, `MIS_Staff` varchar(200) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `tbl_periods` ( `Period_ID` int(11) NOT NULL, `Period_Name` varchar(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `tbl_rooms` ( `RM_ID` int(11) NOT NULL, `RM_Name` varchar(100) NOT NULL, `RM_Desc` varchar(200) NOT NULL, `RM_Available` varchar(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `tbl_weeks` ( `Week_ID` int(11) NOT NULL, `Week_Name` varchar(200) NOT NULL, `Week_Type` varchar(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  11. Evening (Or Morning wherever you are)! Looking for a bit of help as what I am trying to achieve I am unsure if its possible, so I am asking the brains on PHPFreaks. Basically I am developing a booking system, and I have managed to get the system to store the data from the MIS system, however if there is a free session it isn't recorded. For instance, we have 5 sessions a day, but on Mondays the room only has 4 pieces of information recorded as one of them is free. So below is an example of the data within the MIS Data: MIS_ID MIS_Session MIS_Staff MIS_Group 1 MONA:1 ABC GP1 2 MONA:2 DEF GP2 3 MONA:4 GHI GP3 I am able to pull all this information, however it will only pull 4 piece (as I know there is only 4 in the DB) is there anyway to maybe specify within a variable for instance $sessions = 5; then get it so loop through until the values meet: while($session <= mysql_num_rows); Hoping someone can point me in the right direction as I am so close, but feel so far! Thank you in advance to anyone who has any valuable input! Kind Regards, Stuart
  12. Thank you so much for all your help, i've been able to understand your code and adapt elements to make this work for the system I am developing.. I cannot thank you enough. Stuart
  13. Morning, I am looking for some help. What I am trying to do is for each week of the year assign a letter to it, either an A or B week for rotas. I am able to print on screen the weeks for 52 weeks and this part works fine and lists the weeks, and what I want to do from there is use a combobox next to each date so we can allocate a week to it selecting either A or B. The code I have been using and working on I have put on the bottom. Just come a bit stuck and need a little help please. This bit gets me all of the weeks for the next 52 weeks. for($i=1; $i<=52; $i++){ $num = date("Y-m-d", strtotime('Last Monday +'.$i.' week')); echo $num I am now trying to get the below working and can't figure it out... // This is the part to read the submission <?php if(isset($_POST['formSubmit']) ) { $varWeekNow = $_POST['{$num}']; // SQL Bit $sql = "INSERT INTO weeks (Date, Week) VALUES ('$num', '$varWeekNow')"; if (mysqli_query($link, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($link); }} ?> // this is the part to print the weeks and a dropbown box. <?php for($i=1; $i<=52; $i++){ $num = date("Y-m-d", strtotime('Last Monday +'.$i.' week')); echo "<form action=\"index.php\" method=\"post\"> What is this week? " . $num . " <select name=\"{$num}\"> <option value=\"\">Select...</option> <option value=\"A\">A Week</option> <option value=\"B\">B Week</option> </select> <input name=\"formSubmit\" type=\"hidden\" value=\1\" /> <input name=\"submit\" type=\"submit\" /> </p></form>"; } ?> Kind Regards, Stuart
  14. 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.