php and mysql

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
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

php and mysql

Post by YoussefSiblini »

Hi,
I have 3 databases: UK, US and Worldwide
In the the three databases there are 2 tables called: flags and flash

1. I want to output the flags table from the three databases (all data inside that table from the three databases) into a page.
2. I want to output the 2 tables from the three databases (all data inside that 2 tables from the three databases) into a page.

Usually I output from one table and from 1 database by adding this code:

Code: Select all

include "../includes/$database.php";
// This block grabs the whole list for viewing
$sql = mysql_query("SELECT * FROM $table ORDER BY dateadded DESC");
Is there a way to do that, I am new to php and mysql so please can you give me a code sample :))


Youssef
xtiano77
Forum Commoner
Posts: 72
Joined: Tue Sep 22, 2009 10:53 am
Location: Texas

Re: php and mysql

Post by xtiano77 »

If there is a relationship between the database tables you can use an INNER JOIN:

http://www.w3schools.com/sql/sql_join_inner.asp

Otherwise, you can use a UNION:

http://www.w3schools.com/sql/sql_union.asp

Just my two cents. Hope this helps!
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: php and mysql

Post by YoussefSiblini »

Thank you for your reply,

I think I can use inner join since I have relation between tables, but How to get the tables from 2 databases.
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

Re: php and mysql

Post by YoussefSiblini »

Hi,
I sorted it out, I created a table that hold all the info from all the tables and databases and I output that table :((

Thank you

Youssef
Post Reply