Archive for May, 2009
31
May

A problem I encountered recently was, after a short search on the internet, easy to fix.
I was trying to arrange an array in php by it’s keys, but I didn’t know how at first. This is my array

$ray = array('2' => 'second', '1' => 'first', 'a' => 'alpha);

As you noticed the order is 2 – 1 – a. But i want to arrange it to 1 – 2 – a. The only thing I had to do was this:

ksort($ray);

Thats all you need to do. And it will arrange the array by key.

, , ,

21
May

Something i recently discovered, and already regret I didn’t knew this before, makes it much more easier to parse $_POST or $_GET variables into ordinary variables so i can use it properly for mysql insertions.

This is what i used to do:

<?php
   $var1 = mysql_real_escape($_POST['var1']);
   $var2 = mysql_real_escape($_POST['var2']);
   $var3 = mysql_real_escape($_POST['var3']);
?>

Ofcourse we all can see the repeat in this, but i never figured out how to solve that issue.
But ofcourse there is always someone else with a better idea, and I like to share it with you

<?php
  foreach ($_POST as $key => $value){
    $$key = mysql_real_escape_string($value);
  }
?>

And thats simply all. It will put all the $_POST array items into a numerous variables.
The double “$” does what you expect it to do, it makes a variable out of the content of the variable.

When $a = test, than $$a = test2 will result into $test = test2.
It is that easy!

, , , , ,

18
May

Some time ago i discovered jQuery. A great and easy tool to do lots of fun stuff with animations.

But, it also makes Ajax much more simpler.

Just check out this documentation: http://docs.jquery.com/Ajax

, ,

06
May

I already am blogging at phpz.nl but that blog limited me to just PHP.

Because I am working with a lot javascript recently, and wanted to share that as well I decided to make a fresh start, on a new website, with more options for me.

I will keep blogging here, so for both javascript and PHP this will be the place to be! Thanks for joining.