Jump to content

query woes


vampke

Recommended Posts

Hello peoples,

 

I trying to get this query to work but I'm stuck like a madman in a straitjacket :/

 

I have 2 tables: teams and schedule

 

CREATE TABLE `schedule` (
  `id` int( unsigned zerofill NOT NULL auto_increment,
  `team1` varchar(50) NOT NULL default '',
  `team2` varchar(50) NOT NULL default '',
  `team1_score` varchar(5) NOT NULL default '0',
  `team2_score` varchar(5) NOT NULL default '0',
  PRIMARY KEY  (`id`)
)

 

CREATE TABLE IF NOT EXISTS `teams` (
  `id` int(4) unsigned zerofill NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
)

 

team1 and team2 form schedule table are id's from the teams table

 

I need the results from the schedule table ordered alphabetically by team1.name and then by team2.name

 

so far I have

SELECT s.team1, s.team2, s.team1_score, s.team2_score , t.name
FROM schedule s, teams t
WHERE s.team1 = t.id
ORDER BY t.name

 

But I don't know how to get the teamname for team2 this way.

 

Can anyone help me with this?

Link to comment
https://forums.phpfreaks.com/topic/156410-query-woes/
Share on other sites

yes i edited my OP

I have been fiddling around with your code ken, thanks for it, it was really helpful.

 

I have nearly the result i need using

SELECT s.id, s.team1, s.team2, s.team1_score, s.team2_score
FROM schedule s
INNER JOIN teams t ON t.id = s.team1
INNER JOIN teams k ON k.id = s.team2
ORDER BY t.name, k.name

 

The only thing i need now is a way to get t.name and k.name.

 

I uses the following php code:

while ($count < $total_rows) {
	$team1 = mysql_result($resultset,$count,"team1");
	$team2 = mysql_result($resultset,$count,"team2");
	$t1_score = mysql_result($resultset,$count,"team1_score");
	$t2_score = mysql_result($resultset,$count,"team2_score");

 

I tried different things to get the t.name and k.name in my result set but without luck.

 

Any ideas on this?

Link to comment
https://forums.phpfreaks.com/topic/156410-query-woes/#findComment-823633
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.