The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
![]() |
Display both empty & complete fields in results page - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: Display both empty & complete fields in results page (/showthread.php?tid=171) |
Display both empty & complete fields in results page - thedc - May 31st, 2009 First, thank you for your hard work. I'm attempting to recreate a classroom maintenance ticket system using the latest Form Tools. Here's the situation: We have 20 rooms that need to be checked for problems/cleanliness every day. Student workers will fill out a simple form that allows them to enter their name, select a room (dropdown), enter notes, and then submit. All submissions can be edited be all. I need to display daily form results on a page that will show all rooms in a column. The student's name, timestamp, notes, IP address, etc will be in columns next to the rooms. The page needs to show the room (row) even if no data has been submitted yet. Example Form: ![]() Example Results Page: ![]() If I did a search for any given day, I should see the entire room list even if no entries have been made. In the screenshot above, the last four rooms have no submissions. Is there a way to accomplish this kind of results page with Form Tools? Any help would be greatly appreciated. RE: Display both empty & complete fields in results page - Ben - Jun 3rd, 2009 Neat problem! Generating the table with the data isn't tricky at all, but including rows for rooms that don't have any problems reported makes it a little more difficult. Hmm... I think you'll probably need to write a custom PHP page for this. It's a drag, but I can't see a way around it. In broad terms, I'd do this: in your PHP create a single array storing all 20 room numbers. Then, loop through each, querying the database for any info for that room number. For each item, if there's no data, just output an empty row. Sorry this is so very general, but If you need some more help, let me know! :-) - Ben RE: Display both empty & complete fields in results page - thedc - Jun 3rd, 2009 Thanks for your replay. Any help with sample php code would be greatly appreciated. I'm pretty good at figuring things out if I'm given a good start. RE: Display both empty & complete fields in results page - Ben - Jun 12th, 2009 Sure! Sorry for the wait. I'm just at a conference today, but I'll take a look at this when I get home tonight. ![]() RE: Display both empty & complete fields in results page - Ben - Jun 14th, 2009 Ack! Sorry for the wait. Try this (see below for explanation of the code, and what you'll need to do to tweak it for your case): PHP Code: <?php The code is hopefully pretty self-documenting. But let me explain each thing:
Hope this helps...! (and I hope it's fairly clear). - Ben RE: Display both empty & complete fields in results page - thedc - Jun 22nd, 2009 Ben, You are awesome! It worked perfectly. Thank you so much for your help. I am very impressed with the service and usefulness of this forum. I have one last question... for now:-) What code would I need to add to only display the entries from the current day? For example, if I submitted info for each room on a Monday, on Tuesday, all cells in the display page will be clear. Basically, I just want the page to show entries from the current day. Thanks again. RE: Display both empty & complete fields in results page - Ben - Jun 23rd, 2009 Heya, Excellent! Glad it's working out so far. To only display entries on the current day, you'll need to doctor the SQL to limit the results returned. Try this. In your PHP, add these lines. They compute the current day in MySQL-friendly format and the FOLLOWING day. PHP Code: list($year, $month, $day) = split(",", date("Y,m,d")); In the example I listed above, try adding these lines before this line: PHP Code: foreach ($rooms as $room) They only need to be called once, so they needn't be in the loop. Lastly, edit the SQL query to include the date range. So change it to this: PHP Code: $query = mysql_query(" And I think that's it! Unless I messed something up, that should return everything on the current day - regardless of the time the person visits the page. Hope this helps! - Ben |