php – displaying mysql data horizontal at software development blogs

Making Business SUCCESSFUL Every Day

start now

single page

php – displaying mysql data horizontal

This code shows you how to display your mysql data horizontal. The code display 4 products across with two rows, so i display 8 products in total.   

 <?php
    // connect to mysql database server
include ‘config.php’;
include ‘opendb.php’;

    // fetch data. I am only going to display 8 products.
    $res = mysql_query(“SELECT * FROM usedbikes where Publish = ‘Y’  order by BikeID desc LIMIT 8″);
    $num = mysql_num_rows($res) ;

    // calculate table dimensions. This will display 4 products in a line and then another 4 on the next line.
//If you wanted to display more products change the Limit 8 to Limit 12.
     $per_row = 4;
    $rows = (int) (($num + $per_row – 1) / $per_row);
    $count = 0;
 
    //Create Html table
    echo “\n<table>”;
    for ($i = 0; $i < $rows; $i++)
    {
        echo “\n\t<tr>”;
        for ($j = 0; $j < $per_row; $j++)
        {
            if ($count < $num)
            {
                $it = mysql_fetch_array($res);
                $Model= $it["Model"];
                $Make= $it["Make"];
                $Price= $it["Price"];

//I have a bike details page that i’m going to link to. I am also diplaying the bike image. The images are held in folder called ProductImages.

                  $item1 = “<td width=’160′><br><a href=’UsedBikeDetails.php?BikeID=$BikeID’><img border=’0′ src=’ProductImages/$BikeID.jpg’ width=’150′ height=’200′></a><br><font color=’#CA0202′>Model:</font> $band<br><font color=’#CA0202′>Make:</font> $album <br><font color=’#CA0202′>Price:</font> $Price<br><font color=’#CA0202′>Product ID:</font> $BikeID</td>”;  
                     }
            else
 
                $item1 = “”;

            echo “\n\t\t<td>$item1</td>”;
            $count++;
            
        }
        echo “\n\t</tr>”;
    }
    echo “</table>”;
?>

Hope this helps from Software Development Company

  1. this post is very usefull thx!

Leave a Reply