html - Format PHP database data -
what know when grab data database how can format php looks nice. seem getting blank white page , when inspect page google chromes inspect element says i've got 500 internal error.
for example, i'm using pdo connect database. heres code:
<?php $hostname='localhost'; $username='root'; $password='root'; try { $dbh = new pdo("mysql:host=$hostname;dbname=fitness", $username, $password); $sql = "select * fitness"; $fitnessresult = $dbh->query($s ql); $fitness = $dbh->fetchobject($fitnessresult); foreach ($fitness $fit) { $fitnessarray[] = ['name' => $fit->name, 'id' => $fit->description]; } $dbh = null; } catch (pdoexception $e) { echo "error is: " . $e-> etmessage(); }
and here html im using twitter bootstrap framework.
<?php include'inc/connect.inc.php'; ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>fitness</title> <!-- latest compiled , minified css --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> <!-- optional theme --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap- theme.min.css"> <link rel="stylesheet" href="css/style.css" /> <!-- latest compiled , minified javascript --> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="row"> <div class="col-xs-4"> <?php foreach ($fitnessarray $fitness) { echo '<h2>'. $fitness['name'] .'</h2>'; echo '<p>' . $fitness['description'] . '</p>';} ?> </div> <div class="col-xs-8"> <p>dummy text</p> </div> </div> </div> </body> </html>
so how put name h1 tag , description p tag.
thanks
you might want try following keeps objects , fetchs in arrary
$fitnessresult = $dbh->query($sql); $fitnessarray = $fitnessresult->fetchall(pdo::fetch_obj);
then in html
<?php foreach ($fitnessarray $fitness): ?> <h2><?=$fitness->name ?></h2> <p><?=$fitness->description ?></p> <?php endforeach; ?>
Comments
Post a Comment