User Name
|
VBAssassin |
Unique Hits
|
15,157 |
Real Name
|
Scott Thompson |
Location
|
United Kingdom Lincolnshire |
Occupation
|
Web Technologist & Director |
Gender
|
Male |
Age
|
24 Years Old |
WebSite
|
coderprofile.com |
|
|
[PHP] - Lets kill the complex IF
Programming
|
Hi ya guys,
Have you ever nested that many if conditions that your code starts to get quite complicated? Let's give you an example
Just some simple data checks on the $_POST['name'] value. But I'm not happy with that code. For something so simply, why is the code so complex? Let's use a technique with functions to make this much simpler. Then explain how it works in regards to simplifying it.
[code language='php']function get_name() {
//make sure it's set
if (isset($_POST['name']) == false) {
return 'Error Occured'; View In Full
 |
6 Comments |
8.20 out of 10 |
|
|
How to use Memcache on Windows
Web Development
|
I will quickly run you through an example of HOW to use memcache and how it works.
Download Memcache
http://jehiah.cz/projects/memcached-win32/
And load up the .exe - you should just get a blank command box appear - the server is then running on localhost:11211
Install the Memcache extensions in to PHP
If you use something like xamp or easyphp - just enable the memcache exentions (just a case of maybe uncommenting a line or ticking a box like in easyphp).
Code Example
Put that code in a .php page (remember to have the memcache server running). Now simply run the script and it will save my name in memory for 60 seconds! To retrieve the value from memory now put this in the script (within 60 seconds else it will expire from memory).
And you will see that my name is still there!
It's quite simple really. You use add() to add new values to memory where they are View In Full
 |
3 Comments |
8.00 out of 10 |
|
|
PHP Sessions = Member Database Cache
Web Development
|
Let�s go over what a session is.
Sessions
First you call session_start() which gives you a unique ID such as: dde2ds2g67xs2zxjh89s3j8923
Everything you then save to $_SESSION is saved in a file on the server such as:
$_SESSION['message'] = 'hello';
Would be saved to:
tmp/phpsess_dde2ds2g67xs2zxjh89s3j8923
and next time you call session_start(), $_SESSION['message'] will still exist and will have 'hello' in it!
Database Problem
So, you record a members total page hits on your site, and the last time they made a page hit on your site. You keep these stats up to date like this (which is executed on EVERY page hit by the member):
$time = time();
mysql_query("UPDATE `members` SET `timestamp_last_seen` = '{$time}', `hits` = `hits` + 1 WHERE `member` = 'VBAssassin' LIMIT 1;");
Now, all you�re doing is keeping track of the last time they were seen, and the total page hits they have made while logged in.
Solution
You need to keep track of your active sessions u... View In Full
 |
2 Comments |
8.00 out of 10 |
|
|
|
Pick A Random Array Element
Perl
|
2.47 Years Ago
|
0
|
- - -
|
- - -
|
2,593 Chrs
|
|
Randomly pick an element out of an array, returns what was picked and removes the picked element from referenced array.
P.S. I've only been learning Perl for about 8 hours... so don't tell me off i
|
|
|
Bitwise Settings (Class) - Updated 28th Feb 2010
PHP (Hypertext Preprocessor)
|
2.52 Years Ago
|
9
|
- - -
|
- - -
|
5,505 Chrs
|
|
Specify an array of settings, and depending on the combination of settings will return a unique integer. This integer can then be used to workout the settings that were selected to produce that intege
|
|
|
Compare Ratings, and Return Similar Tastes
PHP (Hypertext Preprocessor)
|
2.58 Years Ago
|
2
|
- - -
|
- - -
|
4,894 Chrs
|
|
Lets say you have 5 books... and 5 people rate each of those books. Now you want to find out who's interests, based on each users 5 ratings, are similar to who?
That's what this algorithm calculate
|
|
Please login to post comments. |
|
If it's the "Code Templates" you're talking about, then I dunno why, but it seem very unstable. In like 2 of 10 attempts it returned the "Expended Text" :) I might be looking at the wrong thing tho :)
|
|
thanks for the heads up on the forum reply :) i now know that i don't know
almost anything at all :P i seriously should look up some more tutorials about OOP..
but so far i haven't stumbled across any tutorials detailed enought to really
make me understand the use of it :(
any ideas?
about netbeans,
I didn't know about the "comment block" thingy. I'll try
finding the correct part of the Options so I can look into it :)
But I did know about the "//TODO:". Already changed mine to "//
@todo:", "// @fix:" and "// @remove:" :)
But thanks for all the tips! Really appreciate it :P
|
|
ok.. I take back what I said earlier about NetBeans :) Been using it all night with some theme modifications and the indent settings you showed me... Guess it was more powerful than I thought at first :P
Thanks alot for the tips about this IDE (Y)
|
|
I'm not using Smarty myself either, just saw that line when I had a look at it, and thought maybe you knew what those numbers and stuff ment :)
|
|
oh wow i feel realy stupid right now :P thanks for the quick replies :)
another question i've got for you, that is more general. I'm average skilled in php, but I do not know to much about all this versioning things.
This is an example from Smarty
/* $Id: Smarty.class.php 3149 2009-05-23 20:59:25Z monte.ohrt $ */
what does all that mean? :)
|
|
well i've been trying to change the indent settings.. But I'm prob to stupid to understand what i'm doing wrong :P haha..
I hit Tab and it jumps 4 spaces to the left.. then when i hit backspace i have to remove each space. not just 1 tab :P sorry for my bad explination :) hopefully you understood what i ment :)
|
|
Been trying netbeans for a little while now and it's a decent IDE, but I'm not that impressed. Bad indenting and doesn't even let me override the global options. Indenting is very important to me :P So eclipse is sill my favorite IDE :)
|
|
Yea man sounds good. I had a slight tingly pain running through my arms, but I jumped in early and started going to the gym, they are getting better too. Lucky I got in early though, thanks to you I'm aware of the risks. I hope that didn't sound emotionally lifeless, because i didn't mean for it to sound that way.
Your new system sounds really cool. Will you release concepts and little snippets and ideas of various working parts?
Cya Bud.
|
|
Hehe thanks for the tip. Your CMS to build websites definitely does sound interesting. So I know that business always comes first but do we have a timeline when work will start again on CP? :)
|
|
Hey buddy,
I've been good, currently working at an email marketing place building HTML Email templates, which gets quite boring since all i think about while i'm there is coding PHP. However I've purchased a CMS from someone and I'll be rewriting the script since its all in procedural code and not too crash hot. So yea lots of stuff brewing in my world, how about yours?
Thanks,
Tom
|
|
 |
Scott Thompson (24) United Kingdom, Lincolnshire |
|
VBAssassin has 32 fans
become a fan |
|
 |
|
 |
|