Jump to content

Crossing two tables


onthespot

Recommended Posts

Hey guys.

My code is designed to take the comp_name field from table COMPETITIONS and check the FIXTURES table field COMP for any fixtures where the comp field is the same as comp_name from competitions table and also where the user is the home or away user in the fixtures table.

If rows are found, then the idea is for whatever row is found to be displayed on the fixtures.php page.

 

The following is my code so far.

 

<?php
// select all league competitions
$competition = ("SELECT `comp` FROM `competitions` WHERE `comp_type` = 'league' ");
// user for this part of competition on site
$user = $_SESSION['username'];
// take the competitions and check if there are any fixtures in the fixture table with this name
$comp = mysql_query("SELECT `comp`
FROM `fixtures`
WHERE `comp` = '$competitions'
AND `home_user` = '$user' OR `away_user` = '$user' ");
$num_rows = mysql_num_rows($comp);
// if there are, select them from the competitions table and display
if ($num_rows > 0)
{
	$leagues = mysql_query("SELECT `comp_name`, `game`, `format`
	FROM `competitions`
	WHERE `comp_type` = 'league'
	AND `comp_name` = '$competition'");
	echo"<table cellspacing=\"10\">
		<tr>
		<td>Competition</td>
		<td>Game</td>
		<td>Format</td>
		</tr>";

	while( $row = mysql_fetch_assoc($leagues)) 
		{
		extract($row);
		$info = explode("_",$row[comp_name]);


		echo"
		<tr>
		<td><A HREF='leaguefix.php?comp=$comp_name'>$info[2]</A></td>
		<td>$info[1]</td>
		<td>$info[0]</td>
		</tr>";
		}
	echo"</table>";
	echo mysql_error(); 
}
else 
{

}
?>

 

mysql_num_rows isnt working?

Link to comment
https://forums.phpfreaks.com/topic/170154-crossing-two-tables/
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.