Blog Home | Fife Visits Blog | Fife Rant Blog | Random Computing Stuff Index

Investigating PHP _ Combining Multiple Arrays

I don't write code or webpages for a living but find learning and playing with PHP, XHTML and JavaScript more fun than doing crosswords. I came across computer coding when studying for a degree, but was so busy jumping through hoops set by the examiners that I never really got to actually learn the code in depth. I am now going back to the books I used at the time and working my way through them at my leisure, stopping off and investigating techniques and ideas that I could not explore earlier.
The 2 books that I used were PHP & MySQL for Dummies by Janet Valade(a great reference book); and PHP & MySQL for Dynamic Websites by Larry Ullman (edition 2; edition 4 now out). I also trawled through the PHP manual site and came across lots of helpful stuff on other pages I found from search engine queries.

First Try

When I came to Chpt8 of Ullman's book, I wondered if his script on page 305 could also be written by sending the results of a SELECT query to an array and sorting the array rather than using the SELECT query itself to sort the results.
His scripts can be found at http://www.larryullman.com/books/mysql-visual-quickstart-guide-2nd-edition/#downloads. The one I was interested in was 8.6. The conditionals (if elseif else) are neater in this first version although I wonder if using case conditionals would have been even better. The problem was that the links had to go at the bottom of the page and I wanted them at the top. To fix this I needed to use positioning in the css file (below) which I felt was a bit of a hack. This is one take on that script 8.6 (without the edit or delete bit).

If the pdf doesn't open, go to code pdf.


The css file is named beasts.css
.sort{
position: relative;
left: 0px;
top: 10px;
}
.list{
position:absolute;
top: 30px;
left: 10px;
}

Second Try

This one is less elegant since I had to use 2 sets of conditionals to get it to work. But it doesn't require the css file with the position tags as everything just falls into place more naturally.

If this doesn't open, go to code pdf


I run php and a mysql database on apache server run on Ubuntu 10.10 in VirtualBox.
The structure and table is as per the image below:
database info

All the code has been tested for compliance with the W3C validator and passed OK.