KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
I'm wondering why you're using eval() everywhere.
-
Adding an item/product to a cart just for theory
KevinM1 replied to j.smith1981's topic in Application Design
That's much easier to follow. I'd say that ~8/10ths of programming is organization. Well-written code is code that is well organized which doesn't repeat itself. It should almost read like prose, or, at least, a step-by-step cookbook. -
From a design standpoint, the output buffer is still a bit sloppy. The ideal design is to organize your scripts like so: ALL PHP Proccessing | | | V Output When you process first, you gain many advantages - you separate logic from presentation, you avoid header errors, you can store generated results in variables, simplifying your presentation code a lot. Even though PHP gives you the option to jump in and out of HTML on the fly, it's really not the ideal way to structure your code. I can't tell you how many people I've seen have loops of PHP where they're writing entire forms in straight HTML, with inline JavaScript to boot, wonder why something is broken. Separation of concerns is the way to go.
-
Adding an item/product to a cart just for theory
KevinM1 replied to j.smith1981's topic in Application Design
Just to note, right now your syntax is messy, as you define functions within an if-conditional. Functions should be defined separately from code that's actually supposed to invoke them. They can be in the same file, but shouldn't be defined in another language structure like an if, or a loop. -
You can't have anything sent to the screen before the redirect. That's what the 'Headers already sent' message means - an echo is, ultimately, an HTTP response. And, if you think about it, echoing output to the screen doesn't make much sense in this case because you're going to another page. If you want to display a message, delay, then redirect the user, look into JavaScript which will allow you to use the browser for redirection rather than an HTTP header command.
-
Look at our stickied thread at the top of this subforum: http://www.phpfreaks.com/forums/php-coding-help/header-errors-read-here-before-posting-them/
-
mysql_query only executes a query. It doesn't give you access to the result set. For that, you need to fetch the results: mysql_fetch_array or mysql_fetch_assoc
-
Adding an item/product to a cart just for theory
KevinM1 replied to j.smith1981's topic in Application Design
Yeah, you can post code here. If you're doing it procedurally, have your Cart be an array (which is what the internals of a Cart class would contain anyway). Each Product could also be an array, where its keys represent its properties. So, you could have something like: $cart = array(); $screwdriver = array('Name' => 'Screwdriver', 'Price' => 2.34, => 'Quantity' => 1); $cart[] = $screwdriver; From there, it's easy to check for an existing Product (in this case, a screwdriver), calculate the total price of both a quantity of individual Products and the total price of the entire Cart, and to display it all on the screen. -
Adding an item/product to a cart just for theory
KevinM1 replied to j.smith1981's topic in Application Design
The simplest way, for me, is to have a Cart object which can contain any number of Product objects. When you add a Product, simply have the Cart check to see if a Product of that type already exists. If so, increase the quantity by 1. If not, add all of the Product info. This makes it easy to iterate over the items, too, for display and figuring out prices. -
Yes, you can most certainly return an array from a function. In fact, doing so is the solution to the OP's problem. Smack whoever said you couldn't on the back of the head. To the OP: simply write: return $UserInfo; At the bottom of your function.
-
So, what's the problem? And why are you using the reference operator with your second method?
-
You end your while-loop prematurely. Look at where its ending brace is.
-
It almost sounds like you're referring to variable variables (e.g., $$someVarName), which can get confusing, and is something I avoid for that very reason.
-
Probably just a typo. The 'this' keyword is the only thing which requires the variable-denoting '$'. In fact, I believe you may get a parse error if you have additional '$'s.
-
You could use one of setTimeout() or setInterval(), depending on exactly how you want to go. setTimeout is a one-shot delay, setInterval is a pulse.
-
The red dollar sign is an error. It shouldn't be there.
-
http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_1?ie=UTF8&qid=1297291748&sr=8-1
-
I think the simplest way to do it is to save actual images on the disk, in folders, and to store their paths in a db. That way, you don't have to fuss with worrying about header info when you want to display them. Simply put their path as the src attribute of an img tag, and you're all set. For the rest, it's really a matter of how flexible you want it to be and how much up-front work you're willing to do to get it to work. That said, at the minimum, I think you should keep avatars separate from other images.
-
Also a good option - but what happens when the user enters an apostrophe? Aren't there a few other characters you can't use in keys? I think it'd be better in the long run to use a name you know will be the same every time. True. Regex is always an option, too, but consistent key names are better.
-
Why not simply use str_replace on the keys, turning any spaces into underscores? foreach($atr as $key => $value) { $value = str_replace(' ', '_', $value); // continue from there }
-
session_regenerate_id
-
Not to be snarky, but the best workaround would be to learn PHP. Looking at your code more closely, as it stands right now, the part you've shown will need to be completely rewritten.
-
The onCommandExample1() method uses type hinting to ensure arguments passed in are of the right type. You can't use type hinting except in an argument list. In short, the code at the beginning of your while-loop is gibberish.
-
I suck at design. I'm trying to remedy that. Most of the resources I've found so far either focus on generic photo editing, or design which looks like it comes straight from 1997. So, I was wondering, are there any decent Photoshop resources that focused on modern web design? Note that I'm not looking for general design resources in general. I actually have a good number of resources about design aesthetic. I'm looking for something more focused on using Photoshop specifically for the web. Figuring out graphic sizes for the screen, how to smartly slice up a site, how to ensure accessibility while keeping things looking sharp, nice looking buttons, professional grade sprites, and other tips, tricks, or cool things to do. I have ideas. I just need to learn how to use the program to efficiently translate them from my brain to the screen. Books and/or links would be welcome. Finally, I'm aware of the stickied thread above. It seems to have more or less run its course, which is why I'm not asking in there.
-
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=323713.0