Inserting HTML blocks into HTML document using PHP

Asked

Viewed 782 times

3

I have an HTML interface that should render the query results in the database (PHP+PDO(MYSQL)) how do I inject the results dynamically into the HTML (pure) screen? as queries vary from user to user (one can consult "Tennis" another "dog").

The system works by following the flow: the user accesses an HTML page index where it inserts the query, the query is sent to a file .php that processes the query and returns the results, for an HTML (pure) page that will render the results of the query, it will have the following appearance:

inserir a descrição da imagem aqui

In red: This the div that will encompass the results of the consultations (which can be varied in quantity).

In green: this the image to be returned from the database (its address will be returned and inserted in an img tag).

In blue: the name of the product.

The HTML of the image is as follows:

<div class="row">
    <div id="conteudo" class="col-md-12 span7 text-center"><!-- START Video Content -->
        <div class="video_block">
            <a href="#" class="thumbnail">
                <img src="../../images/temp/1.jpg" alt="produto"/>
            </a>
            <div class="caption">
                <span class="video_title">Titulo</span>
                <br />
            </div>
        </div>
    </div>
</div>
  • You’ll need to use code PHP to enter the data into HTML, not to use variables PHP, do with JS. Pass the PHP for JS and JS to the HTML.

  • @Meuchapeu, forgive my lack of knowledge but did not understand how your solution would work, but thank you very much for your attention in responding

  • You take the variables PHP using JavaScript and passes to the HTML. So yours HTML gets out of code PHP. How is the code that returns the data? Add it to your question.

  • I didn’t realize what you mean by pure HTML. No JS? No PHP?

  • 1

    Pure HTML means not the PHP code inside it

  • So the solution is to use Javascript itself. As @Meuchapeu said.

  • could give an example?

Show 2 more comments

2 answers

1


1

I didn’t test the code, but this must be what you’re looking for.

<?php 
$videoperline = 3;
for($videosarray as $videok => $videov){ //$videosarray array com dados do mysql
    if(($videok%$videoperline==0) || ($videok==0)){ //gera linha com base no numero de items
?>
<div class="row">
    <?php } ?>

    <div id="conteudo" class="col-md-12 span7 text-center"><!-- START Video Content -->
        <div class="video_block">
            <a href="#" class="thumbnail">
                <img src="../../images/temp/<?php echo $videov['thumbnail'];?>.jpg" alt="produto"/>
            </a>
            <div class="caption">
                <span class="video_title"><?php echo $videov['title'];?></span>
                <br />
            </div>
        </div>
    </div>
    <?php if(($videok%$videoperline==0) || ($videok==0)){?>
</div>
<?php } 
} ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.