Jump to content

PHP multiple identical variables on page


lcot

Recommended Posts

I have a page on a website I am building, that has a row of 4 div blocks that each link to the page they grab information from.


 


So in context, I have 4 div blocks with a Country name, country img, country desk limited to 100 characters and a 'read more' button.. All the information of this div is taken from a country_name.php file.


 


BUT, I have 4 different blocks for each different country. So each country has its own country_name.php file with the same variables, just different values.


 


My questions is, is there a way to include each of the 4 php files so I can include the variables on my page to echo the information, but as the variable names for each country are the same, will I have to start and stop the php include. After the stop point, no more variables from that php file will be outputted.


 


If this is the solution, how?! I have no idea how to do this or the best way to approach this problem? Can anyone help me out here?


Thank you!


Edited by lcot
Link to comment
Share on other sites

Sounds like instead of simply including the files and having them dump variables into the global namespace you need to take more control.

 

Functions would likely suffice, as they would enable you to encapsulate whatever it is that needs to be done to generate this data yet they can return it to wherever it is needed.

Link to comment
Share on other sites

have you actually tried your code? each time you include one of your files, any previous variable values would get replaced by the values set within the current included file and the code would run using the current values. this would be no different than using variables like $query/$result/$row for all the separate blocks of query statements you might have on one page.

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.