[SOLVED] php display grid

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

[SOLVED] php display grid

Post by reiqwan »

Hi all;

I have a simple question which has to do with displaying information in a grid:

I have two relational tables which needs to instead of displaying the coulmns id code it needs to display the corresponding columns info.

For instance this is how it looks:

id | category | name
---------------------
1 | 1 | first
2 | 2 | second
3 | 3 | third
4 | 4 | fourth

and this is how i need it to look:

id | category | name
---------------------
1 | type a | first
2 | type b | second
3 | type c | third
4 | type d | fourth

Hopefully you understand what I mean, as I can't seem to find the correct query syntax for this particlur problem.

THanks all
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Re: php display grid

Post by n00b Saibot »

reiqwan wrote:Hopefully you understand what I mean
No, I don't understand what you mean.
Can you please make it clear where you want to display this :?:

EDIT: If displaying on a webpage you can output them in tables to format them in columnar form
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

explanation

Post by reiqwan »

I have two tables in mysql db:

the one is called category -> and has the following columns:
id - category - name

and my other table called files -> has the following columns:
id - categoryid - filename

when i add info to the files table instead of putting the actual name of the category into the category column i put the id of that category into the categoryid column in the files table.

Now when I request the rows of data from my files table I want it to show the category name instead of the categoryid.

How would I do this?

Hopefully that has set sufficient light on the issue.

THanks again
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Code: Select all

SELECT files.id, category.name, files.filename FROM category, files WHERE category.id = files.categoryid
I have used catgory.id assuming you put that into the categoryid column of files table. If you put category column there instead make changes accordingly then :wink:
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

Great

Post by reiqwan »

Thanks that works perfectly!
Post Reply