Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Posts

    1084
  • Joined

  • Last visited

  • Days Won

    126

Posts posted by Antonio Conte

  1. I work with EZ Publish which requires a lot of memory sometimes during installation due to legacy reasons. Therefor I had to do the same recently. Also, due to a recent composer bug, 1 GB of memory was required to update all dependencies on one of our projects. Crazy.

     

    Glad I could help. I agree with Larry that you should maybe look at solving the problem differently. Throwing memory on problems can help out, but it might not be suitable in the feature. Whatever works, I guess.

  2. You need to do an equality check when you output each option, and add 'selected="selected" to the element. The "tricky" part here is that you allow multiple values, so Skills[] (which you could consider naming for easier reference) could contain between zero to N values. You'll therefor need to loop that array, or write a function that helps you with that.

     

    Something along the lines of:

    $driverSkills = $_POST['Skills'][]; // Use key or index to fetch actual driving skills here.
    
    function isSelected( $array, $value )
    {
       foreach ( $array as $option )
       {
          if ( $option == $value ) return true;
       }
       return false;
    }
    
    <option value="Traffic Planner" <? if ( isSelected("Traffic Planner") ? 'selected="selected"' : ''; ?>>Traffic Planner</option>

    The approach is a little naive, but will work. To optimize it, you should consider moving from String values to integers on the option elements. That way, you could be able to both output and check the content in the same operation:

    $drivingSkills = array(
       1 => "LGV Class 1",
       2 => "LGV Class 2"
    );
    
    $selectedSkills = $_POST['skills']['driving']; // Named keys are simpler
    
    <select name="skills['driving']" multiple size="1" id="Combobox1">
    <?php foreach ( $drivingSkills as $value => $name ) : ?>
       <?php if ( isset($selectedSkills[$value]) : ?>
          <option value="<?= $value ?>" selected="selected"><?= $name ?></option>
       <?php else; ?>
          <option value="<?= $value ?>"><?= $name ?></option>
       <?php endif; ?>
    <?php endforeach; ?>
    </select>

    You'll need some more safe-guarding like creating an empty array if $_POST['skills'] is unavailable, but that's all to it.

    • Upvote 1
  3. You need to alter the PHP configuration. The problem is that the script takes too much memory, and therefor gives you a fatal error.

     

    You can get your current limit by:

    php -i | grep memory
    

    Change it by:

    a.) Alter the php.ini configuration file. Up the declaration "memory limit" (and make sure it's uncommended.)

    b.) Or adjust it in a single script adding ini_set('memory_limit', '64M'); to the top your script.

     

    You can also use a flag to do this from the command line, but I don't remember that at the moment. I would recommend just changing php.ini.

    • Upvote 1
  4. You don't actually NEED traits to debug classes. My favorite debugging technique is to put objects or arrays into this:

    echo '<pre>' , print_r($object, true) , '</pre>';

    It should give you object names and display the object internals. If you want object methods, foreach get_class_methods(). If you want the same functionallity inside your objects methods (for whatever reason) simply create methods that call those functions Larry applies with $this as a parameter.

  5. The conversion is not permanent. You need to apply the same function every time you SELECT the timestamp. Also, it looks like you mix up SELECT statements with INSERT statements here.

     

    The general "rule" is:

    1. Save all time data in a unified timestamp. (UTC+0)

    2. Apply conversion only when you display date info.

     

    By doing this, you can also apply user selected time zones, etc, so times can be correct for everyone.

    • Upvote 1
  6. setText is a helper function created to set input on an element. It wraps the if statements for checking if textContent exists ( that's the logic in: textContent !== undefined ) or if you need to use the function innerText. It's basically a short-cut method of choosing the setting method that exists in your browser. (as one of them might not exist) You send in the element ID (<input id="name"> would equal ID = name) and the value to set it to. setText('name', 'Thomas'); would therefor set the input field to 'Thomas' by the best method possible supported by the browser.

     

    var output; is actually the object from the input field with the ID of 'name' in my example. You save it to a variable so you don't have to look for the object each time with a call using document.getElementById(). It's a performance gain. document.getElementById is a native JavaScript function, so you can't 'find it' in your code.

     

    The object saved to the variable output actually IS the HTML. More precisely, it's a node in the document model that makes up a HTML page. Because the variable contains that node (think of it as the input field itself) with functions to alter itself, we simple update the input field by using output.textContent or output.innerText. Those are functions for changing the internal data in the field, and it will be updated visually for the viewer.

     

    Hope that makes the pieces click.

  7. SELECT movies.movie_id, movies.movie_title, movies.movie_desc, studio, scene_name, genre 
    
    FROM movies 
    INNER JOIN studios ON ( movies.studio_id = studios.studio_id )
    INNER JOIN scenes ON ( movies.movie_id = scenes.movie_id )
    INNER JOIN movie_genres AS genres ON ( movies.movie_id = genres.movie_id )
    INNER JOIN movie_actors AS actors ON ( movies.movie_id = actors.movie_id )
    
    ORDER BY movie_id ASC, scene_name ASC

    Structure your queries more to spot errors. SQL is a lot easier to read when you do that.

     

    The error message is very revealing here. Make sure the column is actually called 'genre'. If that doesn't work, make sure you actually have a match for the movie_id in the movie_genres table. As a simple test, try switching the 'INNER JOIN ...' to 'LEFT OUTER JOIN ...' and see if you get a null value in the genre column.

     

    Hope you solve it.

  8. It's absolutely a good idea, though. I use the same, pretty strong, password on every site I don't care about, but a password handler would be beneficial. I think I might just download passwordBox to check it out. I just hate the thought of having to do the extra work of using something like this. :P

×
×
  • Create New...