...

View Full Version : Accessing variable in other php docs



Rabbe
08-12-2012, 12:06 PM
I have this as a function:

function highscore() {
$sql = mysql_query("SELECT * FROM `flaxer` ORDER BY `profit` DESC");
if (mysql_num_rows($sql) <= 0) {
echo "No entries!";
} else {
echo ("User:\tXp Gained:\tSpun:\t picked:\tprofit:\tRuntime:\trank");
$rank = 1;
while ($row = mysql_fetch_assoc($sql)) {
$username = $row['user'];
$xpgained = $row['xpgained'];
$spun = $row['spun'];
$picked = $row['picked'];
$profit = $row['profit'];
$runtime = $row['timerun'];
$user_rank = $rank;
echo('<table border=1 width=300>');
echo('<col width=150>');
echo('<col width=70>');
echo('<col width=70>');
echo('<tr>');
echo('<td>'.$username.'</td>');
echo('<td>'.$xpgained.'</td>');
echo('<td>'.$spun.'</td>');
echo('<td>'.$picked.'</td>');
echo('<td>'.format($profit).'</td>');
echo('<td>'.formatTime($runtime).'</td>');
echo('<td>'.$user_rank.'</td>');
echo('</tr>');
echo('</table>');
$rank++;

}
}
}

which displays a high-score table with ranks etc. But I want to use the rank on the dynamic signature.
this is in another document, so how would I go about calling the rank because $user_rank doesn't work

ImageTTFText($image, 30, 1, 510, 200, $color, $font, $user_rank);

Fou-Lu
08-12-2012, 12:53 PM
You can't use this code.
What you need to do is rewrite a section that generates the data required including the rank, and return that data. This function should then be rewritten to call that function to generate it's data. Output cannot occur when you are pushing image data to the browser (assuming image data is being pushed to the browser). While you can dump the output using output buffering, it won't change that this data is not available anyway since the function disposes it when it completes, so you have to choose what to return from the function. If its a table of data, then its a multidimensional array or an object like a Matrix.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum