Jump to content

[SOLVED] Combining MySql querys


Lamez

Recommended Posts

Ok, so I have a DB filled with tables named after the football conference's, and I want to take all 12 conference's I have, and take the teams in the table and make one giant list, alphabetized.

 

Well, the code I posted below does not work, I get something like this: "Resource id #26Resource id #27Resource id #28Resource id #29Resource id #30Resource id #31Resource id #32Resource id #33Resource id #34Resource id #35Resource id #36"

 

and here is my code,

 

<?php
$path = "";
$title = "Test"; 
$rank = "yes";
//$login = "yes"; 
$admin = "yes"; 

include ($path."main/include/cons/head.php");
$a = mysql_query("SELECT * FROM `Atlantic Coast Conference`");
$b = mysql_query("SELECT * FROM `Big 12`");
$c = mysql_query("SELECT * FROM `Big East`");
$d = mysql_query("SELECT * FROM `Big 10`");
$e = mysql_query("SELECT * FROM `Conference USA`");
$f = mysql_query("SELECT * FROM `Independents`");
$g = mysql_query("SELECT * FROM `Mid-American`");
$h = mysql_query("SELECT * FROM `Mountain West`");
$i = mysql_query("SELECT * FROM `Pac 10`");
$j = mysql_query("SELECT * FROM `SEC`");
$k = mysql_query("SELECT * FROM `Sun Belt`");
$l = mysql_query("SELECT * FROM `WAC`");

$all = $a.$b.$c.$d.$e.$f.$g.$h.$i.$j.$k.$l;

echo $all;

include ($path."main/include/cons/foot.php");
?>

 

Thanks guys!

Link to comment
Share on other sites

All I can say is WTF?!

 

First, there should NOT be separate tables for each conference. There should be a table which lists the conferences then one table for all "teams" which holds specific, one-to-one data for the teams and each team would have a foreign key to the conferences table.

 

However, if you decide not to do it the right way, you should be able to get the results you want using UNION. Althugh I'm not 100% sure you can use a sort on a UNION.

 

<?php
$path = "";
$title = "Test"; 
$rank = "yes";
//$login = "yes"; 
$admin = "yes"; 

include ($path."main/include/cons/head.php");

$query = "SELECT * FROM `Atlantic Coast Conference`
         UNION SELECT * FROM `Big 12`
         UNION SELECT * FROM `Big East`
         UNION SELECT * FROM `Big 10`
         UNION SELECT * FROM `Conference USA`
         UNION SELECT * FROM `Independents`
         UNION SELECT * FROM `Mid-American`
         UNION SELECT * FROM `Mountain West`
         UNION SELECT * FROM `Pac 10`
         UNION SELECT * FROM `SEC`
         UNION SELECT * FROM `Sun Belt`
         UNION SELECT * FROM `WAC`
         ORDER BY team_name";

$result = mysql_query($query) or die (mysql_error());

while ($record=mysql_fetch_assoc($result))
{
 echo implode(' - ', $record) . "<br>\n";
}
include ($path."main/include/cons/foot.php");
?>

Link to comment
Share on other sites

... there is not a right way, just a more efficient way.

 

Hmm... wouldn't a more efficient way be the right way?

 

Do some research on Database Normalization (thousands of references out there) and learn what is meant be a relational database. Without using the "related" functionality within a database you are left with nothing more than glorified spreadsheets.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.