guyfromfl Posted March 2, 2007 Share Posted March 2, 2007 I am working on a project where there is a set of the same data used over and over on multiple pages. So i wanted to make a require_once file that populates the array whenever I need that array in a page. I did but all that happens is a blank page (with the bgcolor i defined in the css) and my error_log doesnt have a record of the request. I am stumped. Here is the idea of what im talking about the require_once (../includes/globals.php): <?php $reason = array (1 => "item1", 2 => "item2", 3 => "item3", 4 => "item4"); ?> one of the files that calls on it <?php // Ive tried with declaring the $reason array and without it require_once(includes/globals.php); /* content until i need to populate a listbox */ for ($i=1; $i<=4; $i++) { echo "<option>".$reason[$i]."</option>"; } sounds simple enough. everything worked great until i made this small change --mark Quote Link to comment Share on other sites More sharing options...
fekaduw Posted March 2, 2007 Share Posted March 2, 2007 well i check it and it works. the only thing u got to do is to put a double quote around the include/globals.php something like this require_once("includes/globals.php"); try this if it helps Quote Link to comment Share on other sites More sharing options...
fekaduw Posted March 2, 2007 Share Posted March 2, 2007 sorry don't forget the <select> tag <?php require_once("globals.php"); echo "<select>"; for ($i=1; $i<=4; $i++) { echo "<option>".$reason[$i]."</option>"; } echo "</select>" ?> Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted March 2, 2007 Author Share Posted March 2, 2007 yea sorry about that in the original code it had ' and changed them to " still same result. and same with the <select> --mark Quote Link to comment Share on other sites More sharing options...
linuxdream Posted March 2, 2007 Share Posted March 2, 2007 try a print_r($reason); above the <select> to be sure the variable is getting there and what the contents are. If that doesn't work, then start with the print_r in the require page...then keep moving it farther away (closer to your <select>)until you discover where the problem is. Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted March 2, 2007 Author Share Posted March 2, 2007 awsome debug tip thanks. it still has the same result so it must be something else in the code. all the syntaxes look good so its probably something stupid i did. thanks anyways guys --mark Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 2, 2007 Share Posted March 2, 2007 i don't think this will make a difference, but it would be better in my opinion if you used a foreach loop instead of a for loop, like this: <?php echo "<select name=\"drop_down_menu\">\n"; foreach($reason as $key => $val){ echo "<option value=\"". $key ."\">". $val ."\n"; } echo "</select>\n"; ?> also, did anything output when you printed the contents of the array? it could be a path related issue. Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted March 2, 2007 Author Share Posted March 2, 2007 yea print_r returned nothing. ive tried severaly different configs of the path still same result. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 2, 2007 Share Posted March 2, 2007 instead of using require_once... just use include() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.