Jump to content

foreach Using GLOBALS Variable


digiman999

Recommended Posts

Hi peeps,
 
      I have this code here in a function.php file.
 
$row = mysqli_fetch_array(mysqli_query($con,"SELECT * FROM releases"));
$GLOBALS ['releaseids']=$row['id']; global $releaseids;
 
I then try & use this within a function
 
function postcontainer(){
global $releaseids;
foreach ($releaseids as $releaseid){
echo "this is the id";}
}}
 
 
Every time however, I keep getting 
 
 Invalid argument supplied for foreach() in...
 
This still applies too if it isn't put inside or outside of a function.
 
Very grateful
digiman 
Edited by digiman999
Link to comment
Share on other sites

Okay, don't even bother trying to do it that way.

 

Pass the values to the function. Plus, a function shouldn't really echo anything, it should just return the data. You don't need a function to do what you're trying to do, just the foreach() wherever your values are already defined.

 

Stop using global completely. Forget that word exists.

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.