Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing variable in other php docs

    I have this as a function:
    Code:
    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
    Code:
    ImageTTFText($image, 30, 1, 510, 200, $color, $font, $user_rank);

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •