Forum Moderators: coopster

Message Too Old, No Replies

PHP Mysql - Table relations

PHP Mysql - Table relations

         

s31s3r

7:02 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



I´m looking for help to extract data from 2 tables.

screenshot--> img134.imageshack.us/img134/8897/tableei1.png

How can i relate the 2 tables to have something like this (using the field id)?

section1.nome
section1.noticias1.nome
section1.noticias2.nome
section1.noticias3.nome
________________________

section2.nome
section2.noticias1.nome
section2.noticias2.nome
section2.noticias3.nome

Thanks!

s31s3r

7:24 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



I'm just posting the table scheme.
thanks!
mysql> select * from noticias;
+----+------+------------+
¦ ID ¦ nome ¦ section_id ¦
+----+------+------------+
¦ 1 ¦ foo ¦ 4 ¦
¦ 2 ¦ barr ¦ 5 ¦
¦ 3 ¦ car ¦ 5 ¦
¦ 4 ¦ far ¦ 4 ¦
¦ 5 ¦ vox ¦ 4 ¦
+----+------+------------+
5 rows in set (0.01 sec)

mysql> select * from sections;
+----+----------+
¦ ID ¦ nome ¦
+----+----------+
¦ 4 ¦ Mundo ¦
¦ 5 ¦ Politica ¦
+----+----------+
2 rows in set (0.03 sec)

Habtom

4:33 am on Mar 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is more of a database question.

Is this the kind of query you are looking for:

SELECT S.nome, N.nome FROM noticias N, sections S WHERE S.id = N.section_id