rbrady Posted October 11, 2006 Share Posted October 11, 2006 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[code]<? $query="SELECT * FROM results"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $team1name[$i]=mysql_result($result,$i,"team1name"); $team2name[$i]=mysql_result($result,$i,"team2name"); $team1score[$i]=mysql_result($result,$i,"team1score"); $team2score[$i]=mysql_result($result,$i,"team2score"); $i++; }?>[/code]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 ? Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 11, 2006 Share Posted October 11, 2006 try this as an alternative way to populate your arrays and see if it helps at all:[code]<?php$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');}?>[/code]what does that get you? Quote Link to comment Share on other sites More sharing options...
rbrady Posted October 11, 2006 Author Share Posted October 11, 2006 great! it worked, thanks so much ;) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 11, 2006 Share Posted October 11, 2006 If you're open to other suggestions on alternative methods, here's how I would do this:[code]<?php$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.?>[/code]Ken Quote Link to comment 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.