JasonLewis
-
Posts
3,347 -
Joined
-
Last visited
Posts posted by JasonLewis
-
-
What is it some kind of club? Just donate 10 bucks if you want in that bad.
-
$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.
-
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.
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.
-
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){
-
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.
-
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).
-
I'm assuming PHPFreaks have modified the theme slightly to add the extra buttons that are not in SMF by default. Over on the SMF site there is a tutorial which shows you how to add more menu buttons to SMF2.
-
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.
-
Surely there is a better way to design your tables so you don't need to do all this mucking around.
-
Why don't you just have a topic_id column and a comment column. That way you don't need to create a new column for every new thread.
-
And besides, I don't think haku was referring to you using PHP to determine the users browser when referring to conditional statements, but Conditional Comments.
If you really need to load a separate stylesheet for IE:
<!--[if IE 6]> Load another stylesheet for IE <![endif]-->
More information can be found here.
-
Providing an absolute path in these circumstances is a far better option then a relative path. In other words.
$small = "/home/user/public_html/admin/imgs/small/90_'.$auto_increment.'.jpg";
Or whatever the path would be for you.
-
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.
-
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.
-
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?
-
Use AJAX, and post the data. A much cleaner approach, and easier to manage requests as well.
-
Ah, from the Land Down Under just like myself. Welcome, hope you enjoy the forums.
-
Have you seen this guy on Chatroulette? Funny stuff: http://www.youtube.com/user/PianoChatImprov
That guys rocks, I laughed so hard when my mate showed me that. Especially when the girl asks him to play Fireflies, she wants him so bad.
-
[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.
-
You, by choice, use IE over FF.
-
I didn't think so, I was too busy thinking WTF and my girlfriend was going "EW WTF!" She got pretty grossed out.
-
Just watched it, that's just f'ed up man.
-
Hooray for SemiApocalyptic.
My parents bought a Wii, biggest waste of money ever. It's sitting in a cupboard now.
-
Oh it's a band, never heard of them. Haha, might have to see what they're like.
Does it work?
in Website Critique
Posted
Mm, like Nightslyr was saying.. Have you ever heard of CSS? I suggest you look into it, and also take a look at other websites that are out there. We're in a new era of web design.