1

I have this code:

<div style="width:100%; position:fixed; z-index:999; top:0; left:0; padding:10px; background-color:#666666; height:50px;">
<h3><button id="inbox_button" >Inbox <?php echo $messages_num; ?></button></h3>
<div id="inbox_div" style="background-color:#eeeeee; width:350px; height:400px; overflow-y:scroll; display:none; margin-top:20px; padding:0px;">
<?php require_once $_SERVER['DOCUMENT_ROOT'].'/admin/includes/menu_messages.php'; ?>
</div>
</div>

i am using require_once to include a php file. the file (menu_messages.php) has the PHP variable $messages_num; in, how can i echo this on the Inbox button - i have echoed it above but its not displaying

6
  • You're echoing it before including the file that contains it? Commented Dec 28, 2013 at 13:21
  • i know, im not sure what i can do to make it work Commented Dec 28, 2013 at 13:29
  • You can not use a variable before it is declared, this is very simple and basic, you should learn php Commented Dec 28, 2013 at 13:29
  • but if i declare the require before i echo the variable, it will show my required file in the wrong place Commented Dec 28, 2013 at 13:32
  • @charliejsford that makes no sense. Read some basic tutorials Commented Dec 28, 2013 at 13:33

2 Answers 2

1

you need to include the other php file before you can call any variables stored within it.

Sign up to request clarification or add additional context in comments.

Comments

0

You should require the file first, the output is blank because the file holding the variable isn't loaded yet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.