If you want to update every second row (actually its updating odd and even rows in MySQL table) then this is a small trick i found on one 7 years old printout.
So the problem with me was that i accidentally updated one enum column on all rows so this table…
+---+---+
| 1 | A |
| 2 | b |
| 3 | A |
| 4 | b |
| 5 | A |
+---+---+
…turned out to have B’s everywhere, but i just wanted to capitalize them where they are…
+---+---+
| 1 | B |
| 2 | B |
| 3 | B |
| 4 | B |
| 5 | B |
+---+---+
…first i got depressed (because manually changing 1000 rows wasnt included in todays plans), so i remember i had something similar many years ago and guess what – found it. Solution was to use mod() to detect if row id was odd or even…
update `table1` set value='A' where MOD(id,2) = 1;
update `table1` set value='B' where MOD(id,2) = 0;
… and voila! my day (night, actually) is saved…
+---+---+
| 1 | A |
| 2 | B |
| 3 | A |
| 4 | B |
| 5 | A |
+---+---+
Of course, it doesnt help you if id’s are mixed or even more sad – no id’s at all. Well, if you know better solution – would be appreciated.
Archive for July, 2010
While using PHPUnit i noticed that my test “image resource” folder couldnt be accessed even thought that it was located ../../resources/images. Not too far away if script is called directly.
PHP’s file_get_contents() and file_put_contents() have a neat attribute called use_include_path that allows from PHP5 to include a common php include path.
On the other hand – unlink(), touch() and other oldsk00l functions dont use include path, so i was in trouble since PHPUnit test case and suite use PHPUnit’s plugin folder on zend/eclipse. It means that there is almost no goddamnway to figure out how to access the folder _relatively_ two levels down if you are located somewhere else in server file tree. Read the rest of this entry »
Folder/directory path manipulation in PHP
Author: Edgars | Filed under: Web Development, phpHave we really come to the point where computer performance evolution in existing mode is not needed for anyone but software/hardware manufacturers? Microsoft extended downgrade right for Windows XP users. Which could be like “whatever” for me since i am a Mac OS X Snow Leopard user, but still – i cannot imagine too – what else is needed for my work (and i spend average 12h per day sitting and glaring into shiny monitor). What else is there so cool unknown and unpredictable that would ignite “wantwantneedmust” fire. Have no idea. Read the rest of this entry »
There are times when provider changes server and doesnt put everything back as it was before. Mostly this concerns PHP error reporting settings.
Of course, in old days nobody took a good care of proper coding so often $array[key] was used instead of $array['key'] and this is just one of the smallest things around.
I promise to write later a basic guide for avoiding common PHP error stuff like inproper use of quotes, also inside regular expressions (shame on you TCPDF, have you ever thought of checking your code with notices turned on? Read the rest of this entry »

