Jump to content

how to display image and data of user from mysql database on grid bootstrap


Recommended Posts

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   
}
<?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

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>';
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.