Alex G.
Alex G.

Reputation: 277

Display certain HTML in an Automatically generated PHP page?

How can I display a certain HTML code in a php generated page.

For example, php will automatically display the name and category of an item, yet I want to add custom pictures to this generated page. Is there any way to do this without creating a separate HTML page to include into the generated page?

I'm hoping for something like a database entry where to add the html part to display. Is it possible?

ps. Sorry if I didn't express my idea in a completely understandable way.

Upvotes: 0

Views: 198

Answers (3)

dimitril
dimitril

Reputation: 393

 <?php 
  //Your php code 
 ?>
   <img src="" />
 <?php
   //Your php code 
 ?>

You can put html in a php file, like the example above.

Upvotes: 0

Max
Max

Reputation: 1040

Just wrap the PHP in your HTML:

<h1>My Test</h1>
<?= $myCategory; ?> - <?= $myItem; ?>
<img src ="mySource" alt="myImg" width="15" height="15" />

This also works for your HTML in your Database:

<p><?= $myDatabaseHTMLContent ?></p>

Cheers, Max

Upvotes: 0

Logan Serman
Logan Serman

Reputation: 29860

Store the image URLs just like you are storing the names and categories. Then you would just do something like:

<span id="name"><?= $name ?></span>
<span id="category"><?= $category ?></span>
<img src="<?= $image ?>" />

Maybe you need to clarify - why do you need different HTML for each page, if the only thing changing are the images?

Keep in mind here I use <?= $foo ?> which is generally considered bad practice, and is just shorthand for <?php echo $foo; ?>.

Upvotes: 1

Related Questions