At the start of this section we wrote code to display a nicely formatted list of articles based on this
array using a mixture of p s p and h t AML the date in P P was hard coded in this array but now we know
how to get an array of data from the database using this code.
We just wrote We can use this code.
Instead of having this hard coded array so we'll start by deleting this array.
Then copying in the p-h P code we just written.
And pasting it in its place.
As mentioned before it's always a good idea to have your application code as separate from your presentation
code as you can.
So although we could mix this all together with the to AML It's cleaner to have it all up here before
the next email begins before we test this.
First we remove this var dump line as we no longer need it and that's it.
The cold here that's looping around the array already uses the column names we defined in the database
so when we view this in the browser we get the list of articles coming from the database.
So we can make a change here in the database.
For example let's add a new record.
Like that
and then won't we go back to our site in the browser.
The page has been updated with the new record.
So now we have a dynamic page that we can update without editing the code at all as the content is coming
from the database.
Let's make one more change for each loop here is inside a u l will not add a list element and loops
around the array.
Outputting a list item element for each array item.
However if there is no data.
In other words the array is empty.
No list items will be printed.
In that case we dont want an empty u l element either so let's add a check for an empty array here and
if it is empty will output a message.
Otherwise will print out the articles as before.
And let's not forget to end the statement down here.
If we look at that in the browser nothing has changed as we have some data.
To test this.
We could use p p madmen to delete all our data.
But there is an easier way.
We can just add a where clause to our esky well that results in an empty resultset like this.
There are no records with an idea of zero as they start from 1.
So now in the browser we get the message saying no articles found.
This is equivalent to when you've just started using a content management system for example and you
haven't created any articles yet.
And now we've successfully tested it we'll remove this temporarily where clause like that and in the
browser now a page is back to printing out the list of articles coming from the database.