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
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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

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.