Jump to content

[SOLVED] Stuck on a function


Daney11

Recommended Posts

Hey guys,

 

I am stuck on how to write this function.

 

Basically i have a table

 

'ladder' and 'teams'

 

In 'ladder' i have

ladderid

ladderteamid

laddernumber

 

in 'teams' i have

teamid

teamname

 

I want a function to grab the name of the team 'teamname' from 'teams' however im selecting the team name like this..

$teamnameQuery = "SELECT * FROM `teams` WHERE `teamid` = $ladderteamid";

 

All the information on ladder.php is in ladder but the teamname is in a seperate table.

 

Any other information you need ill post.

 

Thanks in advanced

 

Dane

Link to comment
https://forums.phpfreaks.com/topic/76229-solved-stuck-on-a-function/
Share on other sites

so something like

 

function getteamname($team_tid)
{
$namequery=mysql_query("select * from teams LEFT JOIN ladder where `teams.team_tid` = 'ladder.ladder_lteamid'");

$nameinfo=mysql_fetch_array($namequery);

    $nameinfo['ladder_lteamid']=stripslashes(trim(htmlspecialchars($nameinfo['team_tname'])));
$nameinfo['team_tname']=stripslashes(trim(htmlspecialchars($nameinfo['team_tname'])));

return $nameinfo['team_tname'];
}

 

but that isnt working ^^ never used that join command lol

the key is teams.team_tid = ladder.ladder_lteamid;

they must match

 

IE

 

teams - team_tid

teamA - 1

teamB - 2

teamC - 3

teamD - 4

 

 

ladder - ladder_lteamid

Atest1  -  1

Atest2  -  1

Atest3  -  1

Atest4  -  1

Btest1  -  2

Btest2  -  2

Btest3  -  2

Btest4  -  3

 

will should return

teamA - Atest1

teamA - Atest2

teamA - Atest3

teamA - Atest4

teamB - Atest1

teamB - Atest2

teamB - Atest3

teamB - Atest4

 

try this

<?php
// Start String Function
function escape_ladder_data($data) {
   global $connect;
   if (ini_get('magic_quotes_gpc')) {
   #$date = stripslashes($data); //TYPEO
   $data = stripslashes($data); //TYPEO FIXED
}
   return mysql_real_escape_string(trim($data), $connect);
}
// End String Function

// Start Get Team Name Function
function getteamname($team_tid)
{
$namequery=mysql_query("SELECT teams.* FROM teams LEFT JOIN ladder ON teams.team_tid = ladder.ladder_lteamid WHERE teams.team_tid=$team_tid;"); //UPDATED

    $nameinfo=mysql_fetch_array($namequery);

    $nameinfo['ladder_lteamid']=stripslashes(trim(htmlspecialchars($nameinfo['ladder_lteamid'])));
$nameinfo['team_tname']=stripslashes(trim(htmlspecialchars($nameinfo['team_tname'])));

return $nameinfo['team_tname'];
}
// End Get Team Name Function

?>

change

$namequery=mysql_query("SELECT teams.* FROM teams LEFT JOIN ladder ON teams.team_tid = ladder.ladder_lteamid WHERE teams.team_tid=$team_tid;"); //UPDATED

to

$namequery=mysql_query("SELECT teams.* FROM teams LEFT JOIN ladder ON teams.team_tid = ladder.ladder_lteamid WHERE teams.team_tid=$team_tid;") or die(mysql_error()); //UPDATED

Parse error: parse error, unexpected T_LOGICAL_OR in D:\ladder_functions.php on line 20

 

with line 20 being

 

$namequery=mysql_query("SELECT teams.* FROM teams LEFT JOIN ladder ON teams.team_tid = ladder.ladder_lteamid WHERE teams.team_tid=$team_tid"); or die(mysql_error();

 

:( thanks for how much you're helping me btw. :)

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.