Jump to content

array problem


guyfromfl

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.