Bruce W...1 wrote:
[color=blue]
> I do a query to MySQL using PHP. Well actually I do too many of them
> which is the problem, it's too slow. I think maybe an inner join or
> something would be better but I can't figure this out.
>
> The web page on which the data is displayed has a list of countries.
> Each country has a label heading under which websites are listed that
> have information on that country. Any given website may appear many
> times (under different countries) if it has information on that country.
>
> I've got three tables. They are:
> country - A list of countries and their id key.
> data_pairs - Country and website id pairs
> data - A list of websites and their id key.[/color]
I'm not sure, but I hope I understood your question correctly. It would
have been nice if you would have provided more information about your
tables or in more readable format (See the example I provided).
# Create tables
create table country(id int, name varchar(255));
create table data(id int, address varchar(255));
create table data_pairs( country_id int,data_id int );
# Insert test material
insert into country values(1,'Finland');
insert into country values(2,'Sweden');
insert into data values( 1, 'www.google.com');
insert into data values( 2, 'www.google.fi');
insert into data values( 3, 'www.google.se');
insert into data values( 4, 'www.google.de');
insert into data_pairs values(1,1);
insert into data_pairs values(1,2);
insert into data_pairs values(2,1);
insert into data_pairs values(2,3);
# Query
select country.id as country_id,name,address
from country,data,data_pairs where
country.id = data_pairs.country_id and
data.id = data_pairs.data_id order by country_id;
# Result
+------------+---------+----------------+
| country_id | name | address |
+------------+---------+----------------+
| 1 | Finland |
www.google.com |
| 1 | Finland |
www.google.fi |
| 2 | Sweden |
www.google.com |
| 2 | Sweden |
www.google.se |
+------------+---------+----------------+
Hope this is what you wanted?