lcot Posted June 19, 2013 Share Posted June 19, 2013 (edited) 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 June 19, 2013 by lcot Quote Link to comment Share on other sites More sharing options...
trq Posted June 19, 2013 Share Posted June 19, 2013 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. Quote Link to comment Share on other sites More sharing options...
lcot Posted June 19, 2013 Author Share Posted June 19, 2013 Okay, how could I implement 'functions' to encapsulate? What is the php process I should do some reading on? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted June 19, 2013 Share Posted June 19, 2013 I would suggest either what trq stated as it would probably be less work with the files you have, or combine everything in one file. If you post the code for one file we should be able to help. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 20, 2013 Share Posted June 20, 2013 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. 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.