singhy Posted August 18, 2014 Share Posted August 18, 2014 hi I am having problems trying to either include php file or execute a php script within <div with a class> which I use for a drop down menu, every bit of help much appreciated, thanks..singhy <h2 class="hidenextdiv"><a href="#">dropdown menu1</a></h2><div class="another dropmenuclass"><h3>Test</h3> want to add my php working code here, have tried includes but no joy, it either breaks the dropdown menu or I am not getting the results back from the database, my script works ok, have tested it separately.<h3> </h3><div style="clear: both;"> </div></div> Quote Link to comment https://forums.phpfreaks.com/topic/290517-running-php-script-within-html-div/ Share on other sites More sharing options...
Ch0cu3r Posted August 18, 2014 Share Posted August 18, 2014 (edited) want to add my php working code here, have tried includes but no joy, it either breaks the dropdown menu or I am not getting the results back from the database, my script works ok, have tested it separately. What can we possibly tell you.... We are not mind readers here You need to give some information such as what it is you are trying to do. What is the drop down menu for. What should be in the drop down. What should the PHP code being doing etc. What is the PHP code not doing that it should be doing etc. With out info we are clueless. Also when posting code please wrap it within tags. Edited August 18, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/290517-running-php-script-within-html-div/#findComment-1488144 Share on other sites More sharing options...
ginerjm Posted August 18, 2014 Share Posted August 18, 2014 (edited) First of all you should NOT do your writing this way. Assuming that your php code is going to build something for you that will then exist inside this html code what you do is this: 1 - in the php section of your script (see?) run some code and assign all of it's pertinent output to a php var. 2 - in the html section of your script (see?) place the php value where this generated output is meant to be. Like this: php code section this code is in my php section - already enclosed in php tags since it IS in the php section. Whatever logic you need to run you do here and simply create a var with the data you get from that code. $myvar = " want to add my php working code here, have tried includes but no joy, "; $myvar .= "it either breaks the dropdown menu or I am not getting the results back from the database,"; $myvar .= "my script works ok, have tested it separately";. (note the .= assignment operators on the last two lines.) html section <!-- this code is NOT in php mode - it is being sent directly to the client --> <h2 class="hidenextdiv"> <a href="#">dropdown menu1</a> </h2> <div class="another dropmenuclass"> <h3>Test</h3> <?php echo $myvar; ?> <h3></h3> <div style="clear: both;">worthless div here</div> </div> That is how you separate html from php for the purposes of simplicity, readability and ease of maintenance. Programmatically it makes much better sense to separate your logic from your presentation which is what this does. Edited August 18, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/290517-running-php-script-within-html-div/#findComment-1488162 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.