lukep11a Posted August 25, 2011 Share Posted August 25, 2011 Hi, I am trying to specify a new variable that points to two columns from a table, I think I need to use an array but not sure how to code it. The reason I want one variable instead of two is because it will be used as a dynamic link for home teams and away teams to link to the team page, hope that makes sense. Here is the code I currently have: <?php $query = "SELECT tr.competition, tr.date, tr.htp, tr.hts, tr.ats, tr.atp, tr.et, tr.htpts, tr.atpts, tth.team as hometeam, tta.team as awayteam FROM test_selections ts LEFT JOIN (test_results tr, test_teams tth, test_teams tta) ON (tth.teamid = tr.hometeam AND tta.teamid = tr.awayteam) WHERE ts.userid = '{$_SESSION['userid']}' AND (tr.hometeam = ts.teamid OR tr.awayteam = ts.teamid) GROUP BY tr.resultid ORDER BY tr.resultid DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $team = array($row['hometeam'], $row['awayteam']); ?> Any help would be very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/245711-arrays/ Share on other sites More sharing options...
xyph Posted August 25, 2011 Share Posted August 25, 2011 <?php $team = array(); while($row = mysql_fetch_assoc($result)) { $team[] = array($row['hometeam'], $row['awayteam']); } print_r($team); ?> You are selecting a lot of information in your query that you don't seem to be using. I suggest removing unnecessary columns to make it more efficient. Quote Link to comment https://forums.phpfreaks.com/topic/245711-arrays/#findComment-1262033 Share on other sites More sharing options...
lukep11a Posted August 25, 2011 Author Share Posted August 25, 2011 I am using the selected columns later on, just didnt think I need to show it all but actually, I'm not sure how to call the array, this is the code I had before that doesn't seem to be working with the new code: <tr> <td width="85" class="fixtures_date"><?php echo $row['date']; ?></td> <td width="30" class="fixtures_comp"><?php echo $row['competition']; ?></td> <td width="135" class="fixtures_home_teams"><?php echo "<a href='data/teams.php?team=$team' title='$team Team Data' />"; echo $team; echo "</a>"; ?></td> <td width="25" class="fixtures_center"><?php echo $row['htp']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['hts']; ?></td> <td width="25" class="fixtures_center">-</td> <td width="25" class="fixtures_center"><?php echo $row['ats']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['atp']; ?></td> <td width="135" class="fixtures_away_teams"><?php echo $row['awayteam']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['et']; ?></td> <td width="50" class="fixtures_center"><?php echo $row['htpts']; ?></td> <td width="50" class="fixtures_center"><?php echo $row['atpts']; ?></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/245711-arrays/#findComment-1262035 Share on other sites More sharing options...
xyph Posted August 25, 2011 Share Posted August 25, 2011 I'd need to see more code. I don't really understand where that data is coming from. Quote Link to comment https://forums.phpfreaks.com/topic/245711-arrays/#findComment-1262037 Share on other sites More sharing options...
lukep11a Posted August 27, 2011 Author Share Posted August 27, 2011 This is the full set of code for the original query: <table width="635" border="0"> <?php $query = "SELECT tr.competition, tr.date, tr.htp, tr.hts, tr.ats, tr.atp, tr.et, tr.htpts, tr.atpts, tth.team as hometeam, tta.team as awayteam FROM test_selections ts LEFT JOIN (test_results tr, test_teams tth, test_teams tta) ON (tth.teamid = tr.hometeam AND tta.teamid = tr.awayteam) WHERE ts.userid = '{$_SESSION['userid']}' AND (tr.hometeam = ts.teamid OR tr.awayteam = ts.teamid) GROUP BY tr.resultid ORDER BY tr.resultid DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $team = $row['team']; ?> <tr> <td width="85" class="fixtures_date"><?php echo $row['date']; ?></td> <td width="30" class="fixtures_comp"><?php echo $row['competition']; ?></td> <td width="135" class="fixtures_home_teams"><?php echo $row['hometeam']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['htp']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['hts']; ?></td> <td width="25" class="fixtures_center">-</td> <td width="25" class="fixtures_center"><?php echo $row['ats']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['atp']; ?></td> <td width="135" class="fixtures_away_teams"><?php echo $row['awayteam']; ?></td> <td width="25" class="fixtures_center"><?php echo $row['et']; ?></td> <td width="50" class="fixtures_center"><?php echo $row['htpts']; ?></td> <td width="50" class="fixtures_center"><?php echo $row['atpts']; ?></td> </tr> <?php } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/245711-arrays/#findComment-1262665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.