I’ve really been trying to figure this out myself, but all tutorials on the internet either doesn’t work, or they are written half… no one explains how you echo out the content.
right now I’m pulling a table of popular searches… I want to display the name, and then the category name underneath it. But problem is, that the searches table stores the categories as ID and not name.
So I need to use a join, that will link the “category_id” column in the “popular_search” table, to the “id” column inside the “categories” table… and then display the “name” column from the “categories” table to display the category name.
No one gives info on how to echo the content, cause both tables have columns with the same name, how do I actually do it? I don’t get it…
This is my current query:
SELECT * FROM popular_search ORDER BY `hits` DESC LIMIT 9
And this my current echo’s, but I need to the replace the id field with the category name from the other table:
<?php echo $item['name']; ?>
<?php echo $item['category_id']; ?>
Using
ASshould work for you:Now it’ll be in your array as
category_name.You can read more here: http://dev.mysql.com/doc/refman/5.0/en/select.html