Jun
26

Conditional field select

Oracle SQL

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Wasted 2 hours trying to do something in many lines when that could have been done using just one line of code.

Here’s the problem I wanted to select and display a value either name or fagtcd (code) or staffid whichever is not null from a table.


ID name     fagtcd  staffid
**********************************
1  Andrew   007     -
2  Zairi    -       00188518
3  Shaun    335     101

For example, for the above the selected values should be:-

Andrew 007
Zairi  00188518
Shaun  335      101

Instead of querying 2 times to see each field is null or not it could have been written in one SQL statement:

A colleague once showed me this a year ago but I’ve forgotten so I’m pasting it here on this blog as a reference to myself :)
$sql = “select fname, coalesce(fagtcd,staffid) from agt_profile

From fname or fagtcd or staffid, only the first field that is not null will be selected. If all the fields are null then no results will be returned.

May
31

White Screen of Death

Uncategorized

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

I read from this from php.about.com

You’ve uploaded your PHP page, and went to view it. Instead of seeing what you expected you see nothing. A blank screen (often white), no data, no error, no title, nothing. You view the source…. it’s blank. What happened?

A. The most common reason for this problem is that you’re missing a character somewhere. By simply leaving out a or } or ; somewhere, your PHP won’t work. You don’t get an error, you will simply get a blank screen.

~ Angela Bradley (PHP White Screen)

Well I encounter this very often in my everyday work as a PHP programmer. However it’s not for the reasons Angela Bradley gives.

Mine is because of the error message has been turned off at the webserver. There is specific reasons for this because of certain legacy codes throwing warning messages which has to be surpressed. I recently also hit this problem while installing WordPress and found a nice fix for it.

It’s very frustrating to debug errors such as this as there is no helpful messages telling you what went wrong. Ways of solving it:

  • turn on the error reporting from php.ini
  • open the Apache error log text file and scroll down to see the last error

Update: Found a solution for the White Screen of Death

May
01

Oracle SQL tip

Oracle SQL

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

The following code copies all the values from one column of a table and inserts them into another table.

More than one column can be selectively chosen and copied.

INSERT ALL
INTO AGT_PROFILE(fagtcd) VALUES (agentid)
SELECT AGTNO agentid
FROM AGENT

Apr
03

SQLite conversion

SQLite

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Note: This solution work in Windows/DOS.

SQLite is a wonderful mini database that can be used by PHP.

I recently tried to use this because it was excellent for running it with PHP for PocketPC. It’s small and you don’t need database connections. The database is file based (extension .db) and all you have to do is point to it.

However one of the biggest problem is most PHP versions can only work with SQLite version 2. You can “Invalid format” if you run PHP and try to read SQLite version 3 database. There are some solutions out there to fix it like installing the correct PHP extensions but it didn’t work for me.

I was still adamant in using SQlite and since version 2 and 3 does not have important difference for me I didn’t mind working with SQLite 2.

This is an easy way to convert one db version to another.

Eg: to convert say, “authentication.db” which is version 3 to version 2. You do this:-

sqlite.gif

The advantage now is that I can develope programs on the PC working with the SQLite database and transfer the PHP files as well as the DB (converted of course) into the Pocket PC once done. That’s just too cool and convenient :D

Files needed:-

  • sqlite2.exe
  • sqlite3.exe
  • Mar
    15

    PHP Blogger

    Uncategorized

    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...

    Hi, I’m a PHP developer and I love this programming language! I will post any interesting material related to PHP here as a blog is the most convenient and fastest way to post something.