Inserting HTML blocks into HTML document using PHP

3

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

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

Inred:Thisisthedivthatwillincludequeryresults(whichcanbevariedinquantity).

Ingreen:istheimagetobereturnedfromthedatabase(itsaddresswillbereturnedandinsertedintoanimgtag).

Inblue:theproductname.

TheHTMLoftheimageisasfollows:

<divclass="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>
    
asked by anonymous 21.01.2015 / 12:42

2 answers

1

Using php only you can use the createDocumentFragment function or creteElement and after that, give an append in the DOM with the appendChild .

However, using JS or JQuery you can easily manipulate the DOM: DOM Manipulation .

    
21.01.2015 / 14:18
1

I did not test the code, but this should 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 } 
} ?>
    
29.04.2015 / 00:14