Jump to content

JasonLewis

Members
  • Posts

    3,347
  • Joined

  • Last visited

Posts posted by JasonLewis

  1. $id = 1;
    
    $example = array();
    $example['cart'][$id] = 1;

    What's happening here is we are creating a multi-dimensional array. The parent index (cart) is an associative array and the child indexes (our ids) are numeric arrays. The value for our child indexes are the quantity.

     

    A print_r would show something like:

    Array (
       [cart] => Array( 
          [1] => 1
       )
    )

    What the add_cart function is doing is checking if the cart sessions already contains the product id, and if it does simply increment its value (adding another to the cart). If it doesn't then enter it in as 1. The foreach loop which is iterating over the array is this:

     

    foreach($_SESSION['cart'] as $id => $qty)

    Because $_SESSION['cart'] holds an array, and the key of that array is the product id and the value is the quantity, it makes sense to loop over each item this way. The function you showed is receiving the $_SESSION['cart'] as a parameter. So somewhere in the code would be this:

     

    $items = total_items($_SESSION['cart']);

    You need to understand though that an associative array is where you associative a value as the key.

    $array = array(
      "name" => "Bill"
    );

    Numeric arrays are where the key is an integer.

     

    Well I hope that explains it some what.

     

    Good luck.

  2. Most IDEs these days will alert you of errors (missing semi-colons, brackets etc) and highlight the affected line and most will add in the brackets for you automatically. Most of them should also have function auto completion and variable auto-completion. Not sure about the viewing window though.

     

    NetBeans does the 3 that I mentioned, it's fairly popular. But any decent IDE will do those 3 things, the only one I am not sure of is the viewing window.

     

    :D

     

    I'll add a bit more... I also use NetBeans for SVN. It's very handy, and it has plenty of plugins to add support for more languages. It manages your projects nicely as well.

  3. And line 37 is this line?

     

    $tmp_rating = $row['rating'] / $row['votes'];

     

    Pretty poor validation here, you'd probably want to make sure that both numbers are greater then 0 before performing any division.

     

    if($row['rating'] > 0 && $row['votes'] > 0){

  4. If you're not familiar with the Gang of Four patterns you're probably not a highly skilled OO developer. I specifically said the test was for OO skill. I of all people would not argue that OO is the only correct programming paradigm in PHP. But, if the person you're interviewing claims to be an expert OO developer, they should be able to answer that question.

     

    Each to their own I suppose then.

  5. Which of the Gang of Four patterns do you consider to be most seldom useful and why do you think that is?

     

    If they respond coherently and don't pee their pants they probably know at least something about how good code (in one of two possible styles anyway) /should/ work, though it's no guarantee they aren't lazy and won't ignore what they know to finish things quickly.

    I'd never heard of the Gang of Four, as I've never really read programming books (reading my first one at the moment though).

     

    Eh, personally, I think it's hard to tell. Unless you can look at some of their projects, including source code so you can quickly browse it and check out how they write (also a lot easier if you can understand the code just a little).

  6. I generally have a timeout field in the database, and if they are inactive for too long then it automatically logs them out. Because there are times where a user may be inactive on a page for a period of time due to them reading the page, you don't want them to be logged out (like jayarsee mentioned).

     

    Another solution is to bind a few of the more popular events, such as mousemove and scroll, to the window element. That way you can fire a JavaScript function whenever they move the mouse or scroll the window. This JavaScript function can then use AJAX to update the database timeout field. To prevent it from doing it every single time the mouse is moved you could set a timeout to run every 5 minutes which sets a variable to true, allowing the AJAX function to be called.

     

    That way users that are inactive for too long (such as going to another tab for an hour or so) will be logged out due to inactivity.

  7. If you know what the height would be for each user you could run your styles inline (or external if you can create a PHP file to parse the CSS), that way you can use PHP to calculate the correct margins.

     

    <?php
      $query = "SELECT * FROM front_page ORDER BY RAND() LIMIT 1";
      $result = mysql_query($query, $conn);
      $row = mysql_fetch_assoc($result);
      $funny_pic_out = $row["funny_pic"];
       
      // obtain the individual user height and width
      list($width, $height, $mime, $attr) = getimagesize('images/funny_pic/' . $funny_pic_out);
    
      $margin_left = round($width / 2) * -1; // you could use ceil() here, but we'll use round
      $margin_top = round($height / 2) * -1; // again, could use ceil.
    ?>
    <div id="first_center">
      <img style="position: absolute; width: <?php echo $width; ?>px; height: <?php echo $height; ?>px; top: 50%; left: 50%; margin: <?php echo $margin_left; ?>px 0 0 <?php echo $margin_right; ?>px" src="images/funny_pic/<?php print $funny_pic_out ?>" alt="" />
    </div>

     

    Not tested, so probably won't work right off the bat. But that's an idea of how you could do it.

  8. Not wasted space at all Lewy (ok maybe decrease height with 20px-25px)! great use of color the red I though could look nice maybe Bold or larger? the text below would be nice if it were aligned full. great job though! nice 2010 design

     

    Thanks fortnox007. Which red needs to be bold or larger? The article title red?

    And the text alignment, you're talking about the article text right? You talking about justifying it? I tried that and it didn't look that flash hot, you can test it by changing the P tag with Firebug.

     

    Thanks for the crit, appreciate it. :)

  9. JavaScript acts client-side, and PHP is server-side. You can't update a PHP variable without reloading the page, unless you use an AJAX request to update a variable.

     

    What exactly are you trying to achieve by updating a PHP variable?

  10. [Vote]: 2

    [Reason]: 2 is just far superior in every design aspect. It looks Halo. However, work on the drop down menu could be done to make it look a bit better, bit more Halo-ish. Also your map comes out in a crappy way, make it a bit smoother.

×
×
  • 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.