Logic: Select PHP with inverted positions in html

0

I would like to pull the information from the database as a title, description and image.

But this way exactly in the script below.

Can anyone help me with logic?

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"><script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>

<div class="row row_topbot">
				<div class="col-sm-12 col-md-6">
					<h2>Titulo</h2>
					<p>Descricao.</p>
				</div>
				<div class="col-sm-12 col-md-6">
					<img src="#imagem1" alt="" alt="img" class="img-responsive" style="float: left">
				</div>
			</div>
			<div class="row row_topbot">
				<div class="col-sm-12 col-md-6">
					<img src="#imagem1" alt="" alt="img" class="img-responsive" style="float: right">
				</div>
				<div class="col-sm-12 col-md-6">
						<h2>Titulo</h2>
					<p>Descricao.</p>
				</div>
			</div>
			<div class="row row_topbot">
				<div class="col-sm-12 col-md-6">
						<h2>Titulo</h2>
					<p>Descricao.</p>
				</div>
				<div class="col-sm-12 col-md-6">
					<img src="#imagem1"  alt="e" class="img-responsive" style="float: left">
				</div>
			</div>
			<div class="row row_topbot">
				<div class="col-sm-12 col-md-6">
					<img src="#imagem" alt="" class="img-responsive" style="float: right">
				</div>
				<div class="col-sm-12 col-md-6">
						<h2>Titulo</h2>
					<p>Descricao.</p>
				</div>
			</div>
    
asked by anonymous 31.08.2017 / 17:29

1 answer

1

Dude, you can do the following, first you connect PDO then you use a for loop, like this:

$pdo = new PDO('mysql:host=WWW.SEUSITE.COM;dbname=NOME_DO_DB;charset=utf8', 'root, '');

$query = $pdo('SELECT * FROM table WHERE 1=1');
$query->execute();
$results = $query->fetchAll(PDO::FETCH_ASSOC);


for($i = 0; $i < $query->rowCount(); $i++): /* FECHE A TAG PHP --> */ ?>
    <!-- TUDO QUE ESTIVER AQUI SERÁ REPETIDO HTML -->
    <div class="row row_topbot">
        <div class="col-sm-12 col-md-6">
        <img src="<?php echo $results[$i]['url_da_imagem']; ?>" alt="" alt="img" class="img-responsive" style="float: right">
    </div>
    <div class="col-sm-12 col-md-6">
        <h2><?php echo $results[$i]['titulo']; ?></h2>
        <p><?php echo $results[$i]['descricao']; ?></p>
    </div>
</div>
<?php /*ABRA PHP E FINALIZE O FOR --> */ endfor; ?>

PDO - > link ALTERNATIVE SYNTAX - > link

I hope I have helped.

    
31.08.2017 / 17:53