Jump to content

Barand

Moderators
  • Posts

    24,603
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. So? To insert $stmt = $pdo->prepare("INSERT INTO mytable (uniform, nameFirst, nameLast) VALUES (:uniform, :nameFirst, :nameLast)"); foreach ($_POST['data'] as $data) { $stmt->execute($data); }
  2. Alternatively, a change to your input naming... <?php if (isset($_GET['data'])) { echo '<pre>', print_r($_GET, 1), '</pre>'; } ?> <form> <input class="form-control" name="data[1][uniform]" type="text" placeholder="Uni #" /> <input class="form-control" name="data[1][nameFirst]" type="text" placeholder="First Name" /> <input class="form-control" name="data[1][nameLast]" type="text" placeholder="Last Name" /> <br> <input class="form-control" name="data[2][uniform]" type="text" placeholder="Uni #" /> <input class="form-control" name="data[2][nameFirst]" type="text" placeholder="First Name" /> <input class="form-control" name="data[2][nameLast]" type="text" placeholder="Last Name" /> <br> <input class="form-control" name="data[3][uniform]" type="text" placeholder="Uni #" /> <input class="form-control" name="data[3][nameFirst]" type="text" placeholder="First Name" /> <input class="form-control" name="data[3][nameLast]" type="text" placeholder="Last Name" /> <br> <input type='submit' name='btnSub' value='Submit'> </form> giving GET = Array ( [data] => Array ( [1] => Array ( [uniform] => 1 [nameFirst] => aaa [nameLast] => bbb ) [2] => Array ( [uniform] => 2 [nameFirst] => ccc [nameLast] => ddd ) [3] => Array ( [uniform] => 3 [nameFirst] => eee [nameLast] => fff ) ) [btnSub] => Submit )
  3. Something like this?... <?php $data = []; foreach ($_GET['uniform'] as $k => $uniform) { $fname = $_GET['nameFirst'][$k]; $lname = $_GET['nameLast'][$k]; $data[$k] = [$uniform, $fname, $lastname]; } ?>
  4. yes, and make sure your php error reporting is on.
  5. I don't see any error check after the query() call. Easier than checking all mysqli calls is to put this line of code before the "new mysqli()" line ... mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
  6. What if you echo the query string to examine the syntax? echo "SELECT * FROM MK_migration_details WHERE mig_bid='".$_SESSION['bid']."'";
  7. Check for mysql error messages print_r($conn->errorInfo()) // PDO echo $conn->error; // mysqli
  8. Probably for a very similar reason as in your previous post. Check for mysqli errors. Put this line of code before you create your mysqli connection then they will all be reported automatically mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
  9. I'm going to say your $stmt->prepare failed, so $stmt does not contain a valid statement object, hence the $stmt->close() failure. Reason for it failing - maybe because you create a table called "todolist" then try to insert into a table called "employees"
  10. Name your inputs as name='str[1]', name='str[2] etc instead os str1, str2 ... Then it's a simple loop when you process the posted data foreach ($_POST['str'] as $i => $value) { if (trim($value) == '') { echo "$i is blank</br>"; // or whatever you want to do with empty ones } }
  11. Telling us what the problem is goes a long way towards getting it resolved.
  12. Simple and easy to debug it may be, but unfortunately it doesn't get past the syntax parser
  13. Use {..} around the complex variables, e.g. echo "<li><a href='{$row['url']}' title='{$row['title']}'><i class='fas fa-user site-nav--icon'></i> Help</a></li>"; ^___________^ ^_____________^
  14. Here's an example showing bookings/available times for 17th Nov 2020 DATA TABLE: jib_reservation TABLE: jib_booking_period +-------+--------+--------+---------------------+---------------------+--------------+ +-----------+------------+----------+ | resid | roomid | userid | start_time | end_time | participants | | period_id | start_time | end_time | +-------+--------+--------+---------------------+---------------------+--------------+ +-----------+------------+----------+ | 1 | 1 | 1 | 2020-11-17 09:00:00 | 2020-11-17 10:30:00 | 6 | | 1 | 08:00:00 | 08:30:00 | | 2 | 2 | 2 | 2020-11-17 08:30:00 | 2020-11-17 10:30:00 | 15 | | 2 | 08:30:00 | 09:00:00 | | 3 | 2 | 3 | 2020-11-17 12:00:00 | 2020-11-17 14:00:00 | 12 | | 3 | 09:00:00 | 09:30:00 | | 4 | 1 | 1 | 2020-11-17 11:00:00 | 2020-11-17 12:00:00 | 5 | | 4 | 09:30:00 | 10:00:00 | | 5 | 3 | 2 | 2020-11-17 15:00:00 | 2020-11-17 17:00:00 | 6 | | 5 | 10:00:00 | 10:30:00 | +-------+--------+--------+---------------------+---------------------+--------------+ | 6 | 10:30:00 | 11:00:00 | | 7 | 11:00:00 | 11:30:00 | | 8 | 11:30:00 | 12:00:00 | | 9 | 12:00:00 | 12:30:00 | | 10 | 12:30:00 | 13:00:00 | | 11 | 13:00:00 | 13:30:00 | | 12 | 13:30:00 | 14:00:00 | | 13 | 14:00:00 | 14:30:00 | | 14 | 14:30:00 | 15:00:00 | | 15 | 15:00:00 | 15:30:00 | | 16 | 15:30:00 | 16:00:00 | | 17 | 16:00:00 | 16:30:00 | | 18 | 16:30:00 | 17:00:00 | +-----------+------------+----------+ CODE <?php require 'db_inc.php'; $db = pdoConnect('test'); $chosen_date = '2020-11-17'; ### ### Get status of bookings on chosen date ### $res = $db->prepare("SELECT r.roomid , concat(p.start_time, ' - ', p.end_time) as slot , u.firstname , v.participants FROM jib_room r CROSS JOIN jib_booking_period p LEFT JOIN jib_reservation v ON r.roomid = v.roomid AND TIME(v.start_time) < p.end_time AND TIME(v.end_time) > p.start_time AND DATE(v.start_time) = ? LEFT JOIN jib_user u USING (userid) ORDER BY slot, roomid" ); $res->execute([ $chosen_date ]); $slots = []; // arrange results into an array foreach ($res as $r) { if (!isset($slots[$r['slot']])) { $slots[$r['slot']] = array_fill_keys(range(1,4),''); // empty room array } $slots[$r['slot']][$r['roomid']] = $r['firstname'] ? "{$r['firstname']} ({$r['participants']})" : '';; } // output array to table $bookdata = ''; foreach ($slots as $s => $rooms) { $bookdata .= "<tr><td>$s</td>"; foreach ($rooms as $user) { $cls = $user ? 'booked' : ''; $bookdata .= "<td class='$cls'>$user</td>"; } $bookdata .= "</tr>\n"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="creation-date" content="11/16/2020"> <title>Bookings</title> <style type='text/css'> table { width: 800px; font-family: verdana, sans-serif; font-size: 11pt; border-collapse: collapse; } th { background-color: black; color: white; padding: 8px; } td { padding: 4px 8px; } td.booked { background-color: red; color: white } </style> </head> <body> <table border='1'> <tr><th>Booking slot</th><th>Room 1</th><th>Room 2</th><th>Room 3</th><th>Room 4</th></tr> <?=$bookdata?> </table> </body> </html> OUTPUT
  15. From the tutorial I linked you to ... This is working in day slots and you are working in 30 minute slots but the principle is exactly the same
  16. Here's an example script <?php require 'db_inc.php'; $db = pdoConnect('test'); /* MY DATA ******************************************************************************************************** TABLE: a_student +------------+----------+---------------------+ | student_id | fullname | logged | +------------+----------+---------------------+ | 1 | Peter | 2020-08-02 17:23:56 | | 2 | Paul | 2020-08-22 23:23:56 | | 3 | Mary | 2020-07-28 22:23:56 | | 4 | Cath | 2020-01-25 04:23:56 | | 5 | Dave | 2020-01-04 18:23:56 | | 6 | Eric | 2020-02-12 07:23:56 | | 7 | Fred | 2020-10-23 06:23:56 | | 8 | John | 2020-07-19 11:23:56 | | 9 | Jane | 2020-07-28 15:23:56 | | 10 | Alec | 2020-05-06 02:23:56 | | 11 | Ben | 2020-04-07 15:23:56 | +------------+----------+---------------------+ *******************************************************************************************************************/ // // Process AJAX request // if (isset($_GET['ajax']) && $_GET['ajax']=='getstudents') { $res = $db->query("SELECT student_id , fullname , logged FROM a_student; "); exit(json_encode($res->fetchAll())); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="creation-date" content="11/16/2020"> <title>Primes</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $("button").click( function() { var dir = $(this).data("dir"); getStudents(dir) }) }) function getStudents(dir) { if (dir == 'asc') { sortfunc = function(a,b) { if ( a.logged < b.logged ) return -1 else if (a.logged > b.logged ) return 1 else return 0 } } else { sortfunc = function(a,b) { if ( b.logged < a.logged ) return -1 else if (b.logged > a.logged ) return 1 else return 0 } } $.get ( "", {"ajax":"getstudents"}, function(resp) { resp.sort(sortfunc) $("#student-list").html("") $(resp).each( function (k, v) { $("#student-list").append("<tr><td>"+v.student_id+"</td><td>"+v.fullname+"</td><td>"+v.logged+"</td></tr>") }) }, "JSON" ) } </script> <style type='text/css'> table { width: 500px; font-family: verdana, sans-serif; font-size: 11pt; } th { background-color: black; color: white; padding: 8px; } td { padding: 4px 8px; } </style> </head> <body> <button data-dir='asc'>Oldest to Newest</button> &emsp; <button data-dir='desc'>Newest to Oldest</button> <hr> <table> <tr><th>ID</th><th>Name</th><th>Date</th></tr> <tbody id='student-list'> </tbody> </table> </body> </html>
  17. You are trying to search for conditions in records that may not exist. As a result the query behaves as though an INNER JOIN were used intead of a LEFT JOIN.
  18. The tutorial I linked you to shows how.
  19. I'd put dates that are bookable in another table, perhaps a temporary table Let's say you want to check next weeks booking. Put Mon to Fri dates for next week into booking_dates. With your four rooms and 18 timeslots, this query will check all 360 available timeslots for each room for each day next week and output those still available SELECT r.roomid , d.date , start_time , p.end_time FROM room r CROSS JOIN booking_dates d CROSS JOIN booking_periods p LEFT JOIN reservation res USING (roomid, date, start_time) WHERE res.roomid IS NULL ORDER BY rddate, r.room, p.start_time;
  20. Perhaps it's something to do with...
  21. The user privileges defined in the mysql database for whichever username you are connecting with.
  22. If you aren't storing the file you need to load it from the tmp_file. Make sure you have the privileges required to run a LOAD DATA query.
  23. $newData = JSON.parse(data); Try commenting out the above line - it shouldn't be necessary as you specified a data-type: json
  24. Storing reservations only, as you have done, is the efficient way to do it. However, as you have discovered, finding those not booked is like asking "Hands up up everyone who isn't here?". Create a fourth table to define time periods (a record for 30 minute slot between 8am and 5pm) Booking_periods : period_id (PK), start_time, end_time Now you have something you can match against to find available slots. Whether you use it in a query or use it to define a PHP array is up to you. You may find this useful
  25. WHERE's don't work correctly on table that you LEFT JOIN to. You need to put the condition in the JOIN Try SELECT [PROD SCHD].[WORK ORDER], [PROD SCHD].[ENTERPRISE], [PROD SCHD].[PART NUMBER], [PPBOMFCB].[ITEM_NUMBER_BOM], [PPBOMFCB].[CATALOGUE_NUMBER_BOM], [PPBOMFCB].[DESCRIPTION_BOM] FROM [PROD SCHD] LEFT JOIN [PPBOMFCB] ON [PROD SCHD].[WORK ORDER] = [PPBOMFCB].[RELEASE_WO_BOM] AND [PPBOMFCB].[CATALOGUE_NUMBER_BOM] LIKE 'FA%' WHERE [PROD SCHD].[WORK ORDER] IS NOT NULL
×
×
  • 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.