How do I post the data I get from SQL into a div in php


bob

I need to make a page to display posts from database. It must have title and text in the post. I've got all the information from the database, but I don't know how to put them into the div. Currently the data I get is set into a table, but I want to put them into a div. Current code: (Note: I have php and sql connection working)

$sql = "SELECT title, txt FROM xxxxx";
$result = $con->query($sql);

   if ($result->num_rows > 0) {
    // output data of each row
    echo "<table><tr><th>Title</th><th>Text</th></tr>";
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>" . $row["title"]. "</td><td>" . $row["txt"]. " </td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}

Also, I'm looking for the bootstrap panel group class but I can't get it to work.

Nikos Takiris

It looks like you forgot to include your div:

   if ($result->num_rows > 0) {
    // output data of each row
    echo "<div><table><tr><th>Title</th><th>Text</th></tr>";
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>" . $row["title"]. "</td><td>" . $row["txt"]. " </td></tr>";
    }
    echo "</table></div>";
} else {
    echo "0 results";
}

Or, if you don't want to include the table but just the div, just do this:

 if ($result->num_rows > 0) {
    // output data of each row
    echo "<div class='title'><h1>Title</h1>";
    while($row = $result->fetch_assoc()) {
        echo "<p>" . $row["title"]. "</p><p>" . $row["txt"]. " </p>";
    }
    echo "</div>";
} else {
    echo "0 results";
}

Related


how do i get data from the table

Ruben Can someone assist me how to get data from a table in Excel 2013? I have a table called Personal: I want to have a control in a cell like this: (I don't know how to add this control in a cell) So I can select data from the table: I googled a lot before a

how do i get data from the table

Ruben Can someone assist me how to get data from a table in Excel 2013? I have a table called Personal: I want to have a control in a cell like this: (I don't know how to add this control in a cell) So I can select data from the table: I googled a lot before a

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

Nancy (C#): How do I get my post data?

Westerlund I am using Corona SDK to post data to my C# server: headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" local body = "color=red&size=small" local params = {} params.headers = headers params.body = bod

How can i get data from already divided div

alex 97 Hi all I want to extract data from div using Jquery. So I have these 3 divs: <div class="wind">Venice,it</div> <div class="wind">Madrid,es</div> <div class="wind">Rome,it</div> In my JS file I want to extract: Venice, it/Madrid, es/Rome, it. What I do

How can i get data from already divided div

alex 97 Hi all I want to extract data from div using Jquery. So I have these 3 divs: <div class="wind">Venice,it</div> <div class="wind">Madrid,es</div> <div class="wind">Rome,it</div> In my JS file I want to extract: Venice, it/Madrid, es/Rome, it. What I do

How can i get the data-itemvalue from the div class?

Zaz How to get data-itemvalue from div class after selection? I tried one with jQuery('#giftcardwrapping'). jQuery options for val(). but no luck <div class="row-fluid"> <div class="span6"> <div class="btn btn-flat btn-block giftcardwrapping-item item

How can i get data from already divided div

alex 97 Hi all I want to extract data from div using Jquery. So I have these 3 divs: <div class="wind">Venice,it</div> <div class="wind">Madrid,es</div> <div class="wind">Rome,it</div> In my JS file I want to extract: Venice, it/Madrid, es/Rome, it. What I do

How can i get data from already divided div

alex 97 Hi all I want to extract data from div using Jquery. So I have these 3 divs: <div class="wind">Venice,it</div> <div class="wind">Madrid,es</div> <div class="wind">Rome,it</div> In my JS file I want to extract: Venice, it/Madrid, es/Rome, it. What I do

How do i get the facebook post id?

a7madx7 How to extract post id after posting post using Facebook method Post() or PostTaskAsync() ? I use JSON.Netsomething like this var postObject = await fb.PostTaskAsync("/me/feed", postArgs); dynamic result = JsonConvert.DeserializeObject((

How do I get my $_Post to work

turquoise I'm trying to get my site to submit an email every time someone sends a message (now I'm struggling to get variables to work...). It's a learning process, so I'm giving it my all here, just trying to teach myself. But don't like global php commands $

How do i get the facebook post id?

a7madx7 How to extract post id after posting post using Facebook method Post() or PostTaskAsync() ? I use JSON.Netsomething like this var postObject = await fb.PostTaskAsync("/me/feed", postArgs); dynamic result = JsonConvert.DeserializeObject((

Ajax POST to PHP - how do I reply?

Joad 49 I have posted an email address from javascript to php via ajax. Then I searched the database in php to find out if the email exists in the database. How can I then send a message back to javascript/html saying that the value exists? Here is what I am u

Ajax POST to PHP - how do I reply?

Joad 49 I have posted an email address from javascript to php via ajax. Then I searched the database in php to find out if the email exists in the database. How can I then send a message back to javascript/html saying that the value exists? Here is what I am u

How do I get 4 bits from a 16 bit data?

Sajal Singh: I use the getShort() method of the byte buffer to get my short value, I convert it to an int and print the binary value, which is a 16-bit data and I need to access from that 16-bit data 4-bit int value. short bitRateShort = buf.getShort(32 + 2);

How do I get python to store data from multiple people?

Tristan 360 I'm trying to make a discord.py async bot that rewards people with brownie points when asked (hehe). It's supposed to be a local bot for me and my friends, but I don't want to update everyone's brownie point into the code every time I restart it. m

How do I get my data back from my IpcMain

Nelz I am creating a drag and drop react and using electron to send and receive my file data. I received senderId and sender in console.log. How can I get the data to appear? What did I miss? Dropzone.js file const [fileNames, setFileNames] = useState([]); co