Display data horizontally from MySQL table

Generally we fetch data from MySQL table and display the fetch records in rows one by one. But sometimes we need to display the records horizontally as per the image below.

Sir Isaac NewtonLeonardo VinchiWilliam Shakespeare
Adolf HitlerSiddhartha GautamaIan McKellen
AbrahamJesus of NazarethWalt Disney

It’s not a tough job. You can see that the records are pulling up and displaying 2 records in a row and after that in the next rows for the next 2 records. The code for such display style is as follows:


Posted

in

by

Tags:

Comments

5 responses to “Display data horizontally from MySQL table”

  1. badmash avatar
    badmash

    I just signed up to your blogs rss feed. Will you post more on this subject?

    1. admin avatar

      Thanks a lot for your feed back. I am out of my blog for some other projects . I will definitely post more on this.

  2. admin avatar

    Thanks for your feedback. I will definitely post more asap 🙂

  3. Aneeq avatar
    Aneeq

    This is the simplest code to select and display records from MySQL database table and display in PHP.

    $cn=mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
    mysql_select_db($db_name,$cn) or die(mysql_error());

    $sql = “SELECT field_name FROM table_name”;
    $rs = mysql_query($sql) or die(mysql_error());

    while($row = mysql_fetch_array($rs)){

    echo $field_name = $row[“field_name”];
    echo “”;

    }
    mysql_free_result($rs);

    Source:
    http://phphelp.co/2012/04/26/how-to-select-and-display-mysql-records-data-in-php/

    OR

    http://addr.pk/acfd

    1. admin avatar

      @Aneeq – your query will display all the records without separating the record set in row wise. In my example you can see that the fetched records are being displayed in row with 2 columns and then goes to next row. Hope this makes sense.

Leave a Reply

Your email address will not be published. Required fields are marked *