Page 3 of 3 First 123
  • Jump to page:
    #31
  1. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,494
    Rep Power
    111
    Now, I do want to point out right away. The code below is not corrected or complete in any way. My goal was to simplify what you had typed to help get a better idea of how simple it should end up. The way you had the lines of PHP in the 2 example lines should not happen. In the occasion you are to do an action like this multiple times, you create a function for such. The way it appears, the only item you need to hand into such function would be the date you wish the line be built for.
    PHP Code:
    <?php
      
    if($d1total >= 5) {
        
    $color 'red';
      } elseif(
    $d1officer == 3) { // What if equals 4?
        
    $color 'yellow';
      } else {
        
    $color 'green';
      }
      
    // Code to populate names in the toast popup
      
    $day '2017-1-2';
      
    $popup NULL;
      
    $sth->execute(array(':day' => $day));
      foreach(
    $sth as $row) {
        
    $popup .= $row['Name'] . "<BR />\n";
      }
    ?>
    <UL>
      <LI><A><?= $holiday?>1</A></LI>
      <LI><A class="<?= $color?>" onclick="Materialize.toast('Block 1 : Jan 2 2018<BR /><?= $popup?>', 'rounded')">2</A></LI>
      <LI>3</LI>
      <LI>4</LI>
      <LI>5</LI>
      <LI>6</LI>
      <LI>7</LI>
      <LI><A class="<?= $color?>" onclick="Materialize.toast('Block 2 : Jan 8 2018<BR /><?= $popup?>', 'rounded')">8</A></LI>
    </UL>
    The 2 PHP sections at top should each be in its own function. The first may be like a day_color() named function, and the other perhaps a list_requests() named function. Both seem to just need simply the date, which can be defined as an array, or simply just an initial date, and increased 1 day each loop for 7 cycles or so. If you are most always intending on using the 2 together as it currently appears, you can group them in the same function, and just have each on its own index or associated name in the returned array.

    Edit: As your example shows, it displays 1-8. Is this list to list all days of the given month? If so, I think our best bet is to focus more on a function to retrieve the needed data first, before we step forward towards building the HTML output. The input for the function would simply be month and year. We then need to create an SQL query to SELECT what we need for that whole month, and for convenience sake, sort by date ASC to make the array build more in our favor. The length of the created array would be either the length of days that month, or how many people are currently requesting off.
    Last edited by Triple_Nothing; October 16th, 2017 at 06:58 PM.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  2. #32
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2016
    Posts
    70
    Rep Power
    2
    Thanks very much. Believe me I am not looking to be spoon fed. And I would like to learn as much as I can about making this properly, and with a lowest chance of me messing something up.

    Going to try and answer everything you mentioned

    $d1officer will only ever be 3 or lower. When the date has 3 officers off (yellow background) no more officers are allowed to choose that day. So it wont ever be more than 3.

    The page that deals with $d#officer and $d#total is a function. But I have never used them before so I am echoing a result from that page. Which is a count of the total staff, and officers off work.

    I guess I didnt realize that those dumps of array - the stuff you see when you <pre>print_r ...</pre> Is that what you are meaning? We can query less specific information and process it with PHP? I always attempt to create very specific queries for the exact data I need.

    I am going to PM you a link to my testing page. It might help you see better what I am trying to do. It will probably help answer the last couple of questions.

    Thanks again so much for all your help! Its amazing for me.
    Last edited by SGC3; October 16th, 2017 at 08:30 PM.
  4. #33
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    2
    Rep Power
    0
    This article might be helpful to you Introduction to PDO
  6. #34
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    12
    Rep Power
    0
    @Saquib Your code is propagating the same thing that many tutorials do. You are creating a major security issue by outputting the internal system errors to the user. That information is of absolutely no use to a user and is only good for a hacker.

    There is no need to litter your codebase by wrapping everything in try/catch blocks. Php is perfectly capable of handling the errors. If you want a custom error handler you would use set-exception-handler

    There is no need to manually close the DB connection. Php will automatically close the connection when the script finishes running.

    You shouldn't SELECT *. Better to specify the column names you want explicitly.

    As of Php 5.4 there is no need to spell out ARRAY. The short syntax is now available [ ]

    No need to use multiple echos when one will do.
Page 3 of 3 First 123
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo