Jump to content

running php script within html div


singhy

Recommended Posts

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>

 

Link to comment
Share on other sites

 

 

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 by Ch0cu3r
Link to comment
Share on other sites

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 by ginerjm
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.