Rationale: Select PHP with positions reversed in html

Asked

Viewed 43 times

0

I would like to pull from the bank information like title, description and image.

But this way exactly in the script below.

Can someone 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>

1 answer

1


Dude, you can do the following, first you connect thePDO then you use a for loop, that way:

$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 -> http://php.net/manual/en/book.pdo.php ALTERNATIVE SYNTAX -> https://secure.php.net/manual/en/control-structures.alternative-syntax.php

I hope I’ve helped.

  • I managed to do it that way anyway! Thank you very much Anderson!

Browser other questions tagged

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