Given that your Dom table contains only positive, not negative, values, you want to generate negatives so that your output table can display them.
This query will give you all possible combinations of origin, domain and species:
SELECT ds.domain, os.origin, ss.species FROM (SELECT DISTINCT domain FROM Dom) ds CROSS JOIN (SELECT DISTINCT origin FROM Dom) os CROSS JOIN (SELECT DISTINCT species FROM Dom) ss
So, to get the "expression values" for each combination, including negatives, do the following:
SELECT completelist.domain, completelist.origin, completelist.species, COALESCE(Dom.species, FALSE) AS found FROM (SELECT ds.domain, os.origin, ss.species FROM (SELECT DISTINCT domain FROM Dom) ds CROSS JOIN (SELECT DISTINCT origin FROM Dom) os CROSS JOIN (SELECT DISTINCT species FROM Dom) ss ) AS completelist LEFT JOIN Dom ON (completelist.domain = Dom.domain && completelist.origin = Dom.origin && completelist.species = Dom.species)
Once you have an array of records from your database, you can then output the table as an html . You would style (using css ) <td> according to the value of the expression. Thus, your result will look something like this:
<table> <thead> <tr> <th>Origin</th> <th>Domain</th> <th>Blahbla_1234</th> <th>wobble_4556</th> <th>piffi_876</th> </tr> </thead> <tbody> <tr> <th>KMT1</th> <th>Kringel</th> <td class='bothexist'> </td> <td class='bothexist'> </td> <td class='onlyprotein'> </td> </tr> <tr> <th>KMT1</th> <th>Helix</th> <td class='bothexist'> </td> <td class='onlyprotein'> </td> <td> </td> </tr> </tbody> <tfoot></tfoot> <table>
The part that is inconvenient reorganizes the data that comes from your request into a structure from which it is easy to display a table.
In any case, although you can use a shell script to do all this, you will probably find it easier to use a higher level language. perl is traditionally used in bioinformatics, and there are many good libraries, including perhaps the most important BioPerl . python and ruby are also popular. php is a very popular and common language, especially adapted to websites and considered very easy to learn (but many programmers object to its various weaknesses).
Hope this points to a useful direction.