Page 1 of 1

[SOLVED] php display grid

Posted: Thu Feb 17, 2005 7:01 am
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

Re: php display grid

Posted: Thu Feb 17, 2005 7:11 am
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

explanation

Posted: Thu Feb 17, 2005 7:25 am
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

Posted: Thu Feb 17, 2005 7:37 am
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:

Great

Posted: Thu Feb 17, 2005 8:05 am
by reiqwan
Thanks that works perfectly!