Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:35:17+00:00 2026-06-05T12:35:17+00:00

I want to display a grid with text like Pinterest does with images. My

  • 0

I want to display a grid with text like Pinterest does with images.
My site is a news feed site were users can upload texts.

The code for displaying and getting the text from the database is:

<?php

//connect

mysql_connect("host","username","password") or die(mysql_error());
mysql_select_db("database_name") or die(mysql_error());

//query the database
$getnews = mysql_query("SELECT * FROM news ORDER BY id DESC") or die(mysql_query());

while ($row = mysql_fetch_assoc($getnews))
{

    //get data
    $id = $row['id'];
    $title = $row['title'];
    $body = $row['body'];
    $date = $row['date'];

    echo "
    <b>$title posted on $date</b><br>
    ";

    echo nl2br($body);

    echo "<hr>
    ";

}



?>

And the code for posting a text is like:

<?php


  //insert category to database
  if(isset($_POST['qty'])) {
    // Fetch and clean the <select> value.
    // The (int) makes sure the value is really a integer.
    $qty = (int)$_POST['qty'];


    // Create the INSERT query.
    $sql = "INSERT INTO `table`(`quantity`)
            VALUES ({$qty})";

    // Connect to a database and execute the query.
    $dbLink = mysql_connect('host', 'username', 'password') or die(mysql_error());
              mysql_select_db('database_name', $dbLink) or die(mysql_errno());

    $result = mysql_query($sql);

    // Check the results and print the appropriate message.
    if($result) {
        echo "Record successfully inserted!";
    }
    else {
        echo "Record not inserted! (". mysql_error() .")";
    }
}






     if ($_POST['post'])
{
    //get data
    $title = $_POST['title'];
    $body = $_POST['body'];

    //check for existance
    if ($title&&$body)
    {
        mysql_connect("host","username","password") or die(mysql_error());
        mysql_select_db("database_name") or die(mysql_error());

        $date = date("Y-m-d");

        //insert data
        $insert = mysql_query("INSERT INTO news VALUES ('','$title','$body','$date')") or die(mysql_error());

        die("Your text has been posted!");

    }
    else
        echo "Please fill out your name and text<p>";
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:35:19+00:00Added an answer on June 5, 2026 at 12:35 pm

    Just write your result as simple <ul><li> elements and style it with CSS. Don’t bother with PHP to create a layout.

    After that you can use the jQuery Masonry plugin to create a Pinterest like layout.

    Your “result display” code will be like this:

    echo '<div id="grid">';
    while ($row = mysql_fetch_assoc($getnews))
    {
    
        //get data
        echo '<div class="item">';
        $id = $row['id'];
        $title = $row['title'];
        $body = $row['body'];
        $date = $row['date'];
    
        echo "<b>$title posted on $date</b>";
    
        echo nl2br($body);
    
        echo "</div>";
    
    }
    echo "</div>";
    

    After that change your final HTML will look like this:

    <div id="grid">
      <div class="item">...</div>
      <div class="item">...</div>
      <div class="item">...</div>
      ...
    </div>
    

    Download jQuery Masonry from the given address and include it in your page like this:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <script src="/path/to/jquery.masonry.min.js"></script>
    

    All sizing of items is handled by your CSS. Items should be floated.

    .item {
      width: 220px;
      margin: 10px;
      float: left;
    }
    

    And at last, call Masonry after your page is loaded:

    $(function(){
      $('#grid').masonry({
        // options
        itemSelector : '.item',
        columnWidth : 240
      });
    })
    

    ;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of images in grid view.I want to display a gallery
I want to display images in a TableView . I can display one image
I want to display some text below each grid image. Please see my code
I want to display and edit some objects in a WPF data grid and
I've following Grid to display data, now when I want to add new record
G'day! I want my WPF ComboBox to display some alternative text when its data-bound
I have a joomla site where users can log in. Once logged in, a
I am having a Grid in WPF application. I want to display all the
I want to display some Arabic text from Right to Left. So I set
Is it possible to display a grid view table when a text or a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.