To show when articles categories on the individual article page we added a method that returns the data
in an array instead of as an article object.
We did this so that we could get the data from both tables in a single query to the database.
However if we want to edit an article in the admin section and also have the categories in this form
which will add shotley.
We need an article object so that we can call the update method on it.
So for the admin edit articles script instead of using this method we just created to get the article
and its categories at the same time.
Let's add a method to the article class to get an articles categories instead.
Let's call it get categories and it won't be a static method as we'll call it on an article object.
Let's add the Eskew L..
Well we'll select all the category table columns joining the article category table using the category
idae and using your where clase to restrict the results to this article only.
We don't need to join to the article table.
We only want category data.
The idea of the article we want is present in the join table.
Then as always with a prepared statement we'll prepare it bind the idees place holder to the I.D. property
of the current object execute it and return an associative array of values.
Let's add a p h.
P duck comment.
And then in the edit article script.
Let's test this by Karl and get on the article object and dumping out the return value.
Now if we edit an article that has categories the new function returns those in an array.
So now we have two ways to get an article with its categories.
The method we added previously which does it all in one query but doesn't return an object and the method
we just added which requires two trips to the database.
Generally speaking it's slightly faster to make a few trips to the database as possible.
But sometimes if your code is clearer and easier to use by having multiple queries like now when we
need an article object then there's no problem with doing this.