Skip navigation.

my php-driven thoughts

about web and something more

Messing around with arrays and variables

, ,

For long time i've been messing around with $_POST, $_GET, $_SESSION and $_COOKIES auto-global arrays, though typing $_POST['my_variable_from_form'] all the time (especially in encapsed or concatenated strings) isn't the biggest pleasure.

So i thought of a solution. I know that i've invented bycicle:
<?php
...
foreach ( $_POST as $key => $value ) {
    ${$key} = $value;
    /**
    * do any additional juggling with $value
    * like cleaning from unneeded tags, adding slashes 
    * or anything else you might think of
    */
}
...
?>

Now i've been listing php manual after some time and found a function that does all the job for me and is even much more flexible!
<?php
...
import_request_variables('p');
...
?>


More on this on the web: http://lt.php.net/manual/en/function.import-request-variables.php

DB problems

, , , ...

Just remembered one thing: if you have home-made-hosting "company" and you provide MySQL databases as data storage server - don't use underscores (_) in databases' names. When you grant someone all priviledges on one db named user_db, then user can create even more databases, like:
  • user0db;
  • user1db;
  • and so on...
I had that problem in my ex-work (Vilnius University IT Center). Thank God, i wasn't responsible for database administration (yet) .)

It's much better to gain such experience at 127.0.0.1 if u know what i mean .)

New and improved drop down list .)

, , ,

Ok, so i couldn't leave this topic, could i ,)

Anyway, remember the sql query with IF?
SELECT id,title,IF(id=given_id,'selected="selected"','') AS selected FROM someTable

Now i added ordering (let's say country list):
SELECT id,country,IF(id=given_id,'selected="selected"','') AS selected FROM countryTable ORDER BY selected DESC,country ASC


Cheers!

P.S. Don't forget to index the table!

something about women and men on Valentine's day

, , ,

Disclaimer: no offence with this story was ment towards female sex. Thank you for understanding and i hope you do realize that this is only the joke which is exploiting dull stereotypes.

=== CUT HERE ===
New super market has opened where women can buy new husband to them selves.
Following rules were hung at the entrance:
1. You can come here only one time;
2. There are six floors in this building, the higher the floor - the better husband's quality is;
3. You can entery any floor and choose a husband there or you can go higher;
4. It's forbidden to go downwards to lower floor if you went higher first.

One woman decided to "go shopping" to that supermarket. And the entry to the first floor she found a poster with text on it "Rich men." and she immediately went up to the second floor. The poster there was saying: "Rich men, who adore children.". Woman decided to go even higher. On the third floor there was a poster saying: "Rich, faithful men, who adore children.". Wow - she thought - "So what's going to be on the next floor?". On the fourth floor she found a poster saying: "Beautiful, rich and faithful men, who adore children.". "It can't be!" - woman thought to her self - "This is only the fourth floor!". She went higher. She was met there with a poster saying: "Exteremly attractive, rich and faithful men, who adore children, helps doing home-cleaning and are really romantic.". Woman was considering entering this floor, but there was one more left. "Real GODs should be on sale there" - she thought. On the sixth floor she read a poster again: "You are 98 567 473rd visitor of this floor. There are no men here. This floor was built only to prove that it's imposible to satisfy women no matter how good men are. Thank you for your visit."

Same type of super-market opened at the other side of the street. For men. With same rules.
First floor's poster: "Women that like sex."
Second floor's poster: "Women that like sex and makes delicious food."
No men went higher...
=== CUT HERE ===

Rotten code - part of programmers evolution?

, ,

I'm sure most of the web-dev'ers and other type of dev'ers some days, months (but most likely years) ago were beginners and didn't know much about programming language they were learning.

I'll take my example.

Lot's of sleepless nights i was sitting in front of Melissa (my first PC, Celeron300, it was 1998). At that time it was kinda fashion thing to be cool (read: 1337), to use linux and be a hacker. Boy, was i naive... I don't remember now how many MBs i've read of tutorials and manuals like 'how to become a hacker.exe' (you can laugh now). Ok, so back to the topic. Coding age came to my life. First off i started with basic HTML (i think it was HTML 4.01) at that time i thought frames are cool. Didn't know anything about CSS'n'stuff. Then i quit it somehow (don't remember how).

After that came mIRC scripting. All summer nights i devoted to my (now)non-existing script NB-script (my nickname was NetBoy at that time, you can laugh again). IRC wars, nukes, ctcp floods were the rage (we didn't have fast isdn, dsl or broad band internet lines). I must say as a 'warrior' (now read: lamer) i was very good and agile.

Some time later a friend of mine offered me to become a web-developer. I knew html quite well at that time. Even started studying css. So a deal was like i write html and a friend of mine paints design. He's one of the best designers i, personally, know at the moment. And then it hit me. html & css with all design was left for my friend and i started to mess with PHP. After few months MySQL came to my sight as well (i wasn't confident enough to use it at beginning). PHP.lt (Lithuanian php developers' portal) started at the same time (it was round late autumn of 2001).

February of 2002 i took part in php.lt party. First party of web-developers. Got aquanted with lots of colegues, learned a lot (i was programming only for half a year, so i was too unexperienced to share my own thoughts).

I was doing lots of projects. Big and small. As i look back to my past projects i smile. When i study the code of my own projects sometimes i even disgust my-self. The code is rotten!

This term i heard first from my cyber-sister (she's native perl speaker, but for some reasons develop in Java). I didn't get a description, but i got the view. It's like when you develop a big project for quite some time and at the ending of project developement (testing-stage most often) you open project files which were developed at the beginning of the project and you see code which you wrote yourself, but now you just can write much more optimized code.

Is it only for me and my sister or it's just that i've improved my coding skills and such short term?
January 2010
S M T W T F S
December 2009February 2010
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30