nong Posted September 7, 2015 Share Posted September 7, 2015 how to display image and data of user from mysql database on grid bootstrap index.php that is picture this my index.php index.php Quote Link to comment https://forums.phpfreaks.com/topic/298086-how-to-display-image-and-data-of-user-from-mysql-database-on-grid-bootstrap/ Share on other sites More sharing options...
hansford Posted September 7, 2015 Share Posted September 7, 2015 Make a connection to the database. Query the database for the information you require. Then use a loop to display each row returned from the query. <?php $con = new PDO('fill in information here'); $sql = "SELECT image_url, project_name, email, skype_id FROM TableName"); foreach($con->query($sql) as $row) { ?> //html mixed with embedded PHP code goes here //where you need to grab something from the database to fill in the blanks use: //<?php echo $row['image_url']; ?> etc etc } Quote Link to comment https://forums.phpfreaks.com/topic/298086-how-to-display-image-and-data-of-user-from-mysql-database-on-grid-bootstrap/#findComment-1520425 Share on other sites More sharing options...
nong Posted September 7, 2015 Author Share Posted September 7, 2015 <?php $servername = "localhost"; $username = "root"; $password = ""; try { $conn = new PDO("mysql:host=$localhost;dbname=userdata", $root, $''); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "CREATE DATABASE myDBPDO"; // use exec() because no results are returned $conn->exec($sql); echo "Database created successfully<br>"; } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } $conn = null; foreach($con->query($sql) as $row) { ?> //html mixed with embedded PHP code goes here: please example code //where you need to grab something from the database to fill in the blanks use: please example code //<?php echo $row['image_url']; ?> etc etc please example code } thank you Quote Link to comment https://forums.phpfreaks.com/topic/298086-how-to-display-image-and-data-of-user-from-mysql-database-on-grid-bootstrap/#findComment-1520429 Share on other sites More sharing options...
Ch0cu3r Posted September 7, 2015 Share Posted September 7, 2015 Why are you executing a CREATE DATABASE query? If you want to get data from your tables your need to use a SELECT query. To have PHP output the results like you index.php template look at the html. Notice every image/product header is contained in a <div class="col-md-2 portfolio-item"> element. This is what you need to output inside the foreach loop containing the data returned by your query, To have the user details displayed in rows of five, you have to contain 5 <div class="col-md-2 portfolio-item"> elements within a <div class="row"> element. To achieve this you could array_chunk to split the array of results return by $con->query into sets of 5. Then you can use two foreach loops to output your results. Example $results = array_chunk($con->query($sql), 5); foreach($results as $rows) { echo '<div class="row">'; foreach($rows as $row) { echo '<div class="col-md-2 portfolio-item">'; // output row data here echo '</div>'; } echo '</div>'; } Quote Link to comment https://forums.phpfreaks.com/topic/298086-how-to-display-image-and-data-of-user-from-mysql-database-on-grid-bootstrap/#findComment-1520448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.