jwer78 Posted February 27, 2006 Share Posted February 27, 2006 Well not sure what Im doing wrong here, so here goes. Im trying to make a dynamic bid module for my league website. People will place bids on players so players can have multiple bids. I am trying to pull the team whos total bid(fbid) is the highest on a given player, and then loop it to the next player; but somewhere I screwed up lol. Any help would be greatly appreciated.[code]$mysql_query = "SELECT Player from nuke_fa_bids group by Player";$res=mysql_query($mysql_query);while($result = mysql_fetch_array($res)){$current_player=$result['Player'];$current_id=$result['id'];$mysql_query = "SELECT * from nuke_fa_bids where Player=$current_player order by Fbid DESC LIMIT 1";$res=mysql_query($mysql_query,$db);$num_rows = mysql_num_rows($res);for($count=0;$count<$num_rows;$count++){$team[$count]=mysql_result($res,$count,"Team");$player_name[$count]=mysql_result($res,$count,"Player");$player_pos[$count]=mysql_result($res,$count,"Position");$fbid[$count]=mysql_result($res,$count,"Fbid");}}$tdbgcolor = array("D6CFCE","0000FF"); for($count=0;$count<$num_rows;$count++){ echo "<tr>"; echo "<td bgcolor=" . $tdbgcolor[$count%2] . " align=left class=boldblacktext><img src=images/smalllogos/". $team .".gif></td>"; echo "<td bgcolor=" . $tdbgcolor[$count%2] . " align=center class=boldblacktext>$player</td>"; echo "<td bgcolor=" . $tdbgcolor[$count%2] . " align=center class=boldblacktext>$player_pos</td></tr>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/ Share on other sites More sharing options...
earl_dc10 Posted February 27, 2006 Share Posted February 27, 2006 well, I couldn't decifer what you were trying to accomplish with this script (sorry), but this may be the problem, change[code]where Player=$current_player[/code]to[code]WHERE Player='$current_player'[/code]Im pretty sure the ' ' are necessaryif that's not the problem, please post the error message you gethope that helps Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12881 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Well that fixed a little something, thank you. Now Im getting "Array" to display. What I need this script to do is go into a table. Find all unique player names then find the highest bidder for each player and display that team, player and position. Right now its just showing the result is still an array so I am still stuck...but atleast its showing something lol. Any additional help would be appreciated, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12898 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Doh..dumb me forgot [$count]. Now its working but its not lopping to get each player. There is 2 test entries on 2 different players each. but its only grabbing 1 of them. Here is the updated code. Again any help would be greatly appreciated. Here is the [a href=\"http://bhfl.maddenfootballleagues.com/modules.php?name=Free_Agent_Leading_Bids\" target=\"_blank\"]URL[/a] if it helps.[code]$mysql_query = "SELECT Player from nuke_fa_bids group by Player";$res=mysql_query($mysql_query);while($result = mysql_fetch_array($res)){$current_player=$result['Player'];$current_id=$result['id'];$mysql_query = "SELECT * from nuke_fa_bids where Player='$current_player' order by Fbid DESC LIMIT 1";$res=mysql_query($mysql_query);$num_rows = mysql_num_rows($res);for($count=0;$count<$num_rows;$count++){$team[$count]=mysql_result($res,$count,"Team");$player_name[$count]=mysql_result($res,$count,"Player");$player_pos[$count]=mysql_result($res,$count,"Position");$fbid[$count]=mysql_result($res,$count,"Fbid");}}$tdbgcolor = array("D6CFCE","0000FF"); for($count=0;$count<$num_rows;$count++){ echo "<tr>"; echo "<td bgcolor=" . $tdbgcolor[$count%2] . " align=left class=boldblacktext><img src=images/smalllogos/". strtolower($team[$count]) .".gif></td>"; echo "<td bgcolor=" . $tdbgcolor[$count%2] . " align=center class=boldblacktext>$player_name[$count]</td>"; echo "<td bgcolor=" . $tdbgcolor[$count%2] . " align=center class=boldblacktext>$player_pos[$count]</td></tr>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12901 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Try this, it eliminates all of your repetitive querys...there is only one now.[code]$mysql_query = "SELECT * FROM nuke_fa_bids ORDER BY Player ASC, Fbid DESC";while ($row = mysql_fetch_array($mysql_query, MYSQL_ASSOC)) { $player = $row['Player']; if (!$result[$player] || $result[$player]['bid'] < $row['bid']) { $result[$player]['bid'] = $row['Fbid']; $result[$player]['team'] = $row['Team']; $result[$player]['position'] = $row['Position']; }}$tdbgcolor = array("D6CFCE","0000FF");$count = 0;echo ' <table border="1" cellpadding="3" cellspacing="0"> <tr> <th>Team</th> <th>Player Name</th> <th>Position</th> <th>Winning Bid</th> </tr>'; foreach ($result as $key => $value) { echo ' <tr style="background-color:' . $tdbgcolor[$count%2] . ';"> <td align="left"><img src="images/smalllogos/'. $value[team] .'.gif"></td> <td align="center" class="boldblacktext">' . $value[player] . '</td> <td align="center" class="boldblacktext">' . $value[position] . '</td> <td align="center" class="boldblacktext">' . $key . '</td> </tr>'; $count++;}echo '</table>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12903 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 It doesnt seem to pull any data. I just get the first table row(column headers) and nothing else. Thanks for the suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12904 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Apparently I removed too much of your script. Change:[code]$mysql_query = "SELECT * FROM nuke_fa_bids ORDER BY Player ASC, Fbid DESC";while ($row = mysql_fetch_array($mysql_query, MYSQL_ASSOC)) { $player = $row['Player']; if (!$result[$player] || $result[$player]['bid'] < $row['bid']) { $result[$player]['bid'] = $row['Fbid']; $result[$player]['team'] = $row['Team']; $result[$player]['position'] = $row['Position']; }}[/code]to:[code]$query = "SELECT * FROM nuke_fa_bids ORDER BY Player ASC, Fbid DESC";$r = mysql_query($query) or die("Could not query: " . mysql_error());while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { $player = $row['Player']; if (!$result[$player] || $result[$player]['bid'] < $row['bid']) { $result[$player]['bid'] = $row['Fbid']; $result[$player]['team'] = $row['Team']; $result[$player]['position'] = $row['Position']; }}[/code]That should fix it. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12905 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Still the same results and it didnt spit out the "Could not query" error. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12907 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Hmmm, changed how the row colors are done, and changed bid to Fbid when it's building the array:[code]$query = "SELECT * FROM nuke_fa_bids";$r = mysql_query($query) or die("Could not query: " . mysql_error());while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { $player = $row['Player']; if (!$result[$player] || $result[$player]['bid'] < $row['Fbid']) { $result[$player]['bid'] = $row['Fbid']; $result[$player]['team'] = $row['Team']; $result[$player]['position'] = $row['Position']; }}$count = 0;echo ' <table border="1" cellpadding="3" cellspacing="0"> <tr> <th>Team</th> <th>Player Name</th> <th>Position</th> <th>Winning Bid</th> </tr>'; foreach ($result as $key => $value) { if (($count % 2) == "0") { $color = "D6CFCE"; } else { $color = "0000FF"; } echo ' <tr style="background-color:' . $color . ';"> <td align="left"><img src="images/smalllogos/'. $value[team] .'.gif"></td> <td align="center" class="boldblacktext">' . $key . '</td> <td align="center" class="boldblacktext">' . $value[position] . '</td> <td align="center" class="boldblacktext">' . $value[bid] . '</td> </tr>'; $count++;}echo '</table>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12909 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Nope, still nothing and still no error. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12910 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Are you sure your query is returning rows? Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12911 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Meaning is there actually data present? Yes there is, I was finally getting the data how I originally coded it but it wasnt looping to get the next player, it was only returning the first player. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12913 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Ok I echoed the $player here is the results[code]Resource id #291Chris RedmanChris RedmanChris RedmanJonathan GoodwinJonathan Goodwin[/code]Shows there is data there... Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12916 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Make sure error reporting is on too:[code]ini_set("error_reporting", "1");ini_set("display_errors", "E_ALL");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12918 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Done. No errors reported. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12920 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Hmm, I haven't a clue...try this:[code]echo "<pre>";$query = "SELECT * FROM nuke_fa_bids";$r = mysql_query($query) or die("Could not query: " . mysql_error());while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { print_r($row);}[/code]Just execute that code. Make sure that the arrays are full of data. If it's possible, can you post a couple of the sub arrays? Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12921 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 This will be a bit long but here you go. Hopefully it helps.[code]Array( [id] => 1 [Team] => Cowboys [Player] => Chris Redman [Position] => QB [Years] => 2 [Thousand] => 0 [Million] => 1.2 [Bthousand] => .100 [Bmillion] => 0 [Fbid] => 0.7 [ip] => xx.xx.xx.xx [user_name] => thecommish)Array( [id] => 2 [Team] => Lions [Player] => Chris Redman [Position] => QB [Years] => 2 [Thousand] => 0 [Million] => 2.0 [Bthousand] => .500 [Bmillion] => 0 [Fbid] => 1.5 [ip] => xx.xx.xx.xx [user_name] => thecommish)[/code]There others on another player for test purposes but I believe this will give you what you need. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12923 Share on other sites More sharing options...
hitman6003 Posted February 28, 2006 Share Posted February 28, 2006 Using this:[code]<?php//$query = "SELECT * FROM nuke_fa_bids";//$r = mysql_query($query) or die("Could not query: " . mysql_error());//while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {$temp = array( Array('id' => '1','Team' => 'Cowboys','Player' => 'Chris Redman','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '1.2','Bthousand' => '.100','Bmillion' => '0','Fbid' => '0.7','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'), Array('id' => '2','Team' => 'Lions','Player' => 'Chris Redman','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '2.0','Bthousand' => '.500','Bmillion' => '0','Fbid' => '1.5','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'), Array('id' => '3','Team' => 'alpha','Player' => 'Ch Redman','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '2.0','Bthousand' => '.500','Bmillion' => '0','Fbid' => '1.0','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'), Array('id' => '4','Team' => 'bravo','Player' => 'Ch Redman','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '2.0','Bthousand' => '.500','Bmillion' => '0','Fbid' => '1.5','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'), Array('id' => '5','Team' => 'charlie','Player' => 'Ch Redman','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '2.0','Bthousand' => '.500','Bmillion' => '0','Fbid' => '2.5','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'), Array('id' => '6','Team' => 'delta','Player' => 'Chris Red','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '2.0','Bthousand' => '.500','Bmillion' => '0','Fbid' => '.5','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'), Array('id' => '7','Team' => 'echo','Player' => 'Chris Red','Position' => 'QB','Years' => '2','Thousand' => '0','Million' => '2.0','Bthousand' => '.500','Bmillion' => '0','Fbid' => '10.5','ip' => 'xx.xx.xx.xx','user_name' => 'thecommish'));foreach ($temp as $row) { $player = $row['Player']; if (!$result[$player] || $result[$player]['bid'] < $row['Fbid']) { $result[$player]['bid'] = $row['Fbid']; $result[$player]['team'] = $row['Team']; $result[$player]['position'] = $row['Position']; }}$count = 0;echo ' <table border="1" cellpadding="3" cellspacing="0"> <tr> <th>Team</th> <th>Player Name</th> <th>Position</th> <th>Winning Bid</th> </tr>'; foreach ($result as $key => $value) { if (($count % 2) == "0") { $color = "D6CFCE"; } else { $color = "0000FF"; } echo ' <tr style="background-color:' . $color . ';"> <td align="left"><img src="images/smalllogos/'. $value[team] .'.gif"></td> <td align="center" class="boldblacktext">' . $key . '</td> <td align="center" class="boldblacktext">' . $value[position] . '</td> <td align="center" class="boldblacktext">' . $value[bid] . '</td> </tr>'; $count++;}echo '</table>';[/code]It works fine for me, so I'm at a loss. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12926 Share on other sites More sharing options...
jwer78 Posted February 28, 2006 Author Share Posted February 28, 2006 Hmm. Maybe its something with the versions of php or something. $Player will echo but if I echo the team, position, or bid nothing will show. May have to go back to square one I guess. Thanks for taking the time to help though, very much appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12937 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.