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
https://forums.phpfreaks.com/topic/247460-quick-question-about-calling-variables/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.