Search code examples
phpmysqlhtmldatabaseauto-generate

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.


Solution

  • 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; ?>.