Jump to content


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


Array returns first letter only

Recommended Posts

Hello, I am trying to make tournament brackets, so I need to put all the info into an array so i can call each team name/score when necessary. I currently am using
$query="SELECT * FROM results";
while ($i < $num) {
then I do like
[code]<? echo($team1name[8]); ?>[/code]or[code]<? echo($team1score[0]."-".$team2score[0]); ?>[/code]
but I only get the first letter returned. I am sure its pulling the correct info, and I am sure the full team name is in the db. if i echo [code]mysql_result($result,$i,"team1name");[/code] i get the full team name, but when i try to call [code]<? echo($team1name[8]); ?>[/code] i just get the first letter. any help ?

Share this post

Link to post
Share on other sites
try this as an alternative way to populate your arrays and see if it helps at all:
$team1name = array();
$team2name = array();
$team1score = array();
$team2score = array();
$sql = mysql_query("SELECT * FROM results");
for ($i = 0; $i < mysql_num_rows($sql); $i++) {
  $team1name[] = mysql_result($sql, $i, 'team1name');
  $team2name[] = mysql_result($sql, $i, 'team2name');
  $team1score[] = mysql_result($sql, $i, 'team1score');
  $team2score[] = mysql_result($sql, $i, 'team2score');

what does that get you?

Share this post

Link to post
Share on other sites
If you're open to other suggestions on alternative methods, here's how I would do this:
$teams = array();
$q = "select * from results";
$rs = mysql_query($q) or die("Problem with query: $q<br>" . mysql_error());
while($rw = mysql_fetch_assoc($rs)) {
  $teams[$rw['team1name']] = $rw['team1score'];
  $teams[$rw['team2name']] = $rw['team2score'];
echo '<pre>' . print_r($teams,true) . '</pre>'; // just to show what the array $teams has in it.


Share this post

Link to post
Share on other sites


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.