Page 1 of 1

php and mysql

Posted: Tue Aug 30, 2011 1:56 pm
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

Re: php and mysql

Posted: Tue Aug 30, 2011 6:08 pm
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!

Re: php and mysql

Posted: Tue Aug 30, 2011 6:32 pm
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.

Re: php and mysql

Posted: Tue Aug 30, 2011 7:00 pm
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