Topic: Trying to add user info in viewtopic.php

Hi,

I'm trying to add some info between the user info and contact links in posts in viewtopic.php

This is the code I added and for some reason it stops me from being able to see anyone elses posts except for the first one. I'm still new to PHP and editing stuff and such so I could be doing things in a completely bizarre way. So my question is why is this doing what it is doing?

<?php if (count($user_info)) echo "\t\t\t\t\t".implode('</dd>'."\n\t\t\t\t\t", $user_info).'</dd>'."\n"; ?>
$sqlkb = "SELECT * FROM `Player` WHERE (PlayerName = '".$cur_post['username']."')";
        $resultkb = mysql_query($sqlkb);
        $PlayerStats = mysql_fetch_row($resultkb);

        $sqlkb = "SELECT * FROM `Involved` WHERE (PlayerID = '".$PlayerStats[0]."')";
        $resultkb = mysql_query($sqlkb);
        $TotalKills = mysql_num_rows($resultkb);

        $sqlkb = "SELECT * FROM `Kill` WHERE (PlayerID = '".$PlayerStats[0]."')";
        $resultkb = mysql_query($sqlkb);
        $TotalLosses = mysql_num_rows($resultkb);

        $sqlkb = "SELECT * FROM `Corp` WHERE (CorpID = '".$PlayerStats[5]."')";
        $resultkb = mysql_query($sqlkb);
        $Corp = mysql_fetch_row($resultkb);

        if($PlayerStats[0] == NULL) {
        } else {
            echo '<dd>';
            echo '<dd> </dd>';
            echo 'Corp: <a href="http://mysite.com/?mode=corp&id='.$PlayerStats[5].'&view=1&kn=0">'.$Corp[1].'</a><br />';
            echo 'Points: '.$PlayerStats[4].'<br />';
            echo 'Kills: <a href="http://mysite.com/?mode=player&id='.$PlayerStats[0].'&kn=0&view=1">'.$TotalKills.'</a><br />';
            echo 'Losses: <a href="http://mysite.com/?mode=player&id='.$PlayerStats[0].'&kn=0&view=2">'.$TotalLosses.'</a>';
            echo '<dd> </dd>';
            echo '</dd>';
        }
    } else {
    }
<?php if (count($user_contacts)) echo "\t\t\t\t\t".'<dd class="usercontacts">'.implode('  ', $user_contacts).'</dd>'."\n"; ?>

The original code looks like:

<?php if (count($user_info)) echo "\t\t\t\t\t".implode('</dd>'."\n\t\t\t\t\t", $user_info).'</dd>'."\n"; ?>
<?php if (count($user_contacts)) echo "\t\t\t\t\t".'<dd class="usercontacts">'.implode('  ', $user_contacts).'</dd>'."\n"; ?>

Many thanks for any help.

Re: Trying to add user info in viewtopic.php

I'll tell you the reason, but I'll also tell you why what you're doing is bad. tongue
The reason: the viewtopic.php call to $db->query is passed with a second parameter. That parameter makes the query use mysql_unbuffered_query. You can't call mysql_query while mysql_unbuffered_query is processing unless you want to abort the unbuffered query.
Why your code is bad: you're executing 4 queries for every post in a topic. That means if the user is viewing 25 posts at once, you're executing 100 extra queries. The best way to do this would be to add the queries as joins to the regular query (although I'd link Player and users more closely than through username to be more efficent)