Jump to content

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/
Share on other sites

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 necessary

if that's not the problem, please post the error message you get

hope that helps
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12881
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12898
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12901
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12903
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12905
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12909
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12921
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12923
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/3691-loops-not-working/#findComment-12926
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.