Jump to content

Quick question about calling variables


amg182

Recommended Posts

Apologies for such a silly question.... Been away from php for a long time...

 

How can i call a variable from a position above where the variable is set? I need a variable to echo out near the top of my page but its defined near the bottom of my script.

 

As you can see i am tryin to echo the amount of rows found from the query below.

 

<?php

echo $num_rows;



$query = "SELECT  Name,  FROM table";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){

$num_rows = mysql_num_rows( $result );
}
?>

 

Thanks in advance

Link to comment
Share on other sites

User defined functions and classes are parsed first, therefor they are available to use any any line regardless of where they are defined.

 

This is not true when the function must be included from another file, and you try to call the function before you include the file.

 

Variable definitions and function calls are execute top to bottom, always.

Link to comment
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.