I've been working with Twitter with the intention of grabbing a user's followers and displaying them in a grid format. The picture below illustrates how I'd like the output to be arranged:
The code that I currently have attempts to use HTML tables, however it just prints out the name, then the picture underneath and so on. I have a feeling I might have to use nested tables or something but I can't figure it out. Here is my code:
<table>
<?php foreach ($users as $user) {
$userScreenName = $user -> screen_name;
$userName = $user -> name;
$userImage = $user -> profile_image_url;
$userDescription = $user -> description;
?>
<tr>
<td>
<?php echo $userName; ?>
</td>
</tr>
<tr>
<td>
<?php echo "<img src = ".$userImage.">"; ?>
</td>
</tr>
<?php
}
?>
</table>
How can I make my output look like my picture (small blocks of name above picture arranged side by side in a grid)?
i would rather use divs insted of tables, because u dont have to create as many columns as you want in your grid, just change the width of one element and they show next to each other, depends on the parents element width.
here is example: grids example
so your code wil look like this
<?php foreach ($users as $user) {
$userScreenName = $user -> screen_name;
$userName = $user -> name;
$userImage = $user -> profile_image_url;
$userDescription = $user -> description;
?>
<div class="name">
<?php echo $userName; ?>
<div class="picture">
<img src="./PATH/<?php echo $userImage; ?>" />
</div>
</div>
<?}?>
<style>
.name {
position:relative;
float:left;
width: 49%;
height: 100px;
border: 1px solid;
text-align:center;
vertical-align:middle;
}
.picture {
width: 80%;
height: 60%;
display: table;
margin: 0 auto;
border: 1px solid;
}
</style>
hope it helps. And sorry for my english :)
<table>
<?php foreach ($users as $user) {
$userScreenName = $user -> screen_name;
$userName = $user -> name;
$userImage = $user -> profile_image_url;
$userDescription = $user -> description;
?>
<tr>
<td>
<?php echo $userName; ?>
</td>
<td>
<?php echo "<img src = ".$userImage.">"; ?>
</td>
</tr>
<?php
}
?>
</table>
Keep in mind that if you have an odd number of friends to add then the LAST table celle will need to be added and be blank
So to give you a pseudo code example you would end up with something like
<table>
<tr>
<td>
<!-- your data here -->
</td>
If NumberOfFriends Mod 2 > 0 Then
<td>
<!-- your data here -->
</td>
Else
<td>
<!-- Blank table cell here -->
</td>
End of If statement
</tr>
</table>
You need to display every alternate user with slightly different markup. Users with even numbered indices will be displayed as the first td element in a row, while users with odd numbered indices will be displayed as the second td in the row.
<table>
<?php foreach ($users as $i => $user) {
$userScreenName = $user -> screen_name;
$userName = $user -> name;
$userImage = $user -> profile_image_url;
$userDescription = $user -> description;
if ($i % 2 == 0) :
?>
<tr>
<td>
<?php
echo $userName;
echo "<img src = ".$userImage.">";
?>
</td>
<?php else : ?>
<td>
<?php
echo $userName;
echo "<img src = ".$userImage.">";
?>
</td>
</tr>
<?php
endif;
}
?>
<div id="container">
<?php foreach ($users as $user) {
$userScreenName = $user -> screen_name;
$userName = $user -> name;
$userImage = $user -> profile_image_url;
$userDescription = $user -> description;
?>
<div class="user">
<div class="user_name">
<?php echo $userName; ?>
</div>
<div class="user_image">
<?php echo "<img src = ".$userImage.">"; ?>
</div>
</div>
<?php
}
?>
</div>
And your css would be like the following:
#container
{
width: 400px;
}
.user
{
float: left;
width:50%;
}
.user_name, .user_image
{
width: 100%;
}
why not include a div inside the table's cells, with a span for the name and a start a new line with css or a br? you can centre the cell's contents with CSS
Try to output something like this:
<table>
<tr>
<td>
<div>
<span class="user-name">NAME</span>
<img class="user-face" src=""/>
</div>
</td>
<td>
<div>
<span class="user-name">NAME</span>
<img class="user-face" src=""/>
</div>
</td>
</tr>
</table>
and the styles:
.user-name {
width: 10em;
display: table-cell;
text-align: center;
}
.user-face {
width: 10em;
height: 10em;
}
Assuming of course that they have an even number of friends... :) You'll have to add an empty td to the end if not!
EDIT: this time based entirely on divs and including the PHP. Will handle odd numbers of friends too :)
<div id="user-data">
<?php
$cellPosition = "left";
foreach ($users as $user) {
$userScreenName = $user->screen_name;
$userName = $user->name;
$userImage = $user->profile_image_url;
$userDescription = $user->description;
if ($cellPosition == "left") {
echo "<div class=\"user-table-row\">\n";
}
echo "<div class=\"cell $cellPosition\">\n";
echo " <span class=\"user-name\">$userName</span>\n";
echo " <img class=\"user-face\" src=\"$userImage\"/>\n";
echo "</div>";
if ($cellPosition == "right") {
echo "</div>";
$cellPosition = "left";
}
else {
$cellPosition = "right";
}
}
?>
</div>
the styles:
<style>
#user-data {
margin:2em;
}
div.user-table-row {
margin: 2em;
width: 24em;
clear: right;
}
div.cell {
width:10em;
display: table-cell;
text-align: center;
margin-bottom: 2em;
}
div.left {
float: left;
}
div.right {
float: right;
}
span.user-name {
width: 10em;
}
img.user-face {
width: 10em;
height: 10em;
}
</style>
Related
I have problem in my task where I suppose to display my record in horizontally with 3 columns
Unfortunately, my display is become vertical.
The task require us to use modulus (%) operator in order to display the records. The records are stored in database (id, title, picture, category, author). There are 11 books that store in database. Here is my PHP code:
<?php
include_once('config.php');
$result = mysqli_query($mysqli, "SELECT * FROM books ORDER BY id ASC");
?>
<style>
img {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
width: 200px;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding-left: 10px;
}
.p3 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding-left: 10px;
color: blue;
}
</style>
<div class="container">
<center>
<h1>Koleksi Buku Peribadi</h1>
<table>
<?php
$x=11;
$y=3;
$i=$x % $y;
while($i && $book = mysqli_fetch_array($result)) {
?>
<tr>
<td>
<img src="Gambar-buku/<?php echo $book['picture'];?>">
<p class='p2'>Penulis:<span class='p3'> <?php echo $book['author'];?> </span>
<br> <i><?php echo $book['category'];?></i>
</p>
<center><button type="button">Details</button> </center>
</td>
</tr>
<?php
$i++; }
?>
</table>
</center>
</div>
Modulus is useful when you need to equally divide items into several categories.
Formally: index_of_category = index_of_item % number_of_categories
Practically: In your case, you have 3 categories (columns). For item with index i, you find index of its column with i % 3.
For making table layout work, you then need to:
print tr opening tag for every item belonging in column with index 0
print tr closing tag for every item belonging in column with index 2.
In my example, you can change number of columns easily by modifying $numberOfColumns variable.
<div class="container">
<center>
<h1>Koleksi Buku Peribadi</h1>
<table>
<?php
$numberOfColumns = 3;
for ($i = 0; (($book = mysqli_fetch_array($result)) !== null); $i++) {
$printRowOpeningTag = $i % $numberOfColumns === 0;
$printRowClosingTag = $i % $numberOfColumns === $numberOfColumns - 1;
if ($printRowOpeningTag) {?>
<tr>
<?php } ?>
<td><img src="Gambar-buku/<?php echo $book['picture'];?>">
<p class='p2'>Penulis:<span class='p3'> <?php echo $book['author'];?> </span>
<br> <i><?php echo $book['category'];?> </i>
</p>
<center><button type="button">Details</button> </center>
</td>
<?php if ($printRowClosingTag) { ?>
</tr>
<?php } ?>
<?php
} ?>
</table>
</center>
</div>
I have view file on my app there is code array I want to get first object of that array without going in loop.
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
$result is array of object I'm getting from a form. In below you can clearly see I'm chunking it to 3 more array and looping though individual objects and getting their details to html for example.
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
I want to get the first object details let's say want get $product->product_name of first object of result array without going in loop how to achieve that.
here is complete view file code.
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 0px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<div class="footer">
Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?>, $ Rate : Rs. <?php echo $usd; ?> </div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: auto 5px 5px 0; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 100px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:100px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
<?php $GLOBALS['a']= $product->product_id; ?>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
ok man as i said u need to change your way of writing codes but about your specific question use this:
$result = array('a', 'b', 'c', 'd', 'e');
reset($array);
$first = current($array);
you can check this:
http://php.net/manual/en/function.reset.php
http://php.net/manual/en/function.current.php
But still about your way of coding. u should soon go to MVC or such ways of programming so u should separate your view and coding logics
like u may have a page like view_profile.php which is going to show user's information. in regular coding u have this:
view_profile.php:
<?php session_start();
// you check sessions to see if the user is logged in and has the right to view this page.
// like:
if ($_SESSIONS['is_user_logged_in']){
$username=$_SESSIONS['username'];
$name=$_SESSIONS['name'];
// ....
}else{
header('location: ./login.php');// if user is not authenticated u redirect to login page
exit();// prevents the rest of codes to be shown and executed
}
?>
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
But in a better way u can do it like this:
you have files like
'view_profile.htm' // holds the HTML
'view_profile.php // holds the PHP logic
'inc.php' // holds some useful functions that help you in writing PHP logic
view_profile.htm
<html>
<head>
<title>View <?php echo $name; ?>'s profile</title>
</head>
<body>
<div>Name: <span><?echo $name; ?></span></div>
......
</body>
</html>
inc.php
<?php
function ses_start(){
if(!session_id()){
session_start();
}
}
function ses_get($key){
ses_start();
if(!empty($_SESSION[$key])){
return $_SESSION[$key];
}
return NULL;
}
function ses_set($key,$val){
$_SESSION[$key]=$val;
}
function is_user_loggedin(){
ses_start();
if(!empty(ses_get('is_user_loggedin')){
return true;
}
return false;
}
function go($to){
header('location: '.$to);
exit();
}
//and lots of useful functions that help u connect and work with data base.
view_profile.php
<?php
include('inc.php');
if(is_user_loggedin(){
$username=ses_get('username');
$name=ses_get('name');
//...
}else{
go('login.php);
}
include('view_profile.html); // and u call the .htm file that holds the HTML the view file)
?>
this was a simple sample of separating codes logic(php codes) from views(html tags)
and also u may search about MVC Model-View-Controller and try working with simple MVC frameworks.
I am implementing the printing of pages in HTML.
My aim is if a table will not be accommodated in the same page, the whole table will be transferred to the next page. How do i do this. i have this code.. please help me.
here is my CSS part.
<style type="text/css">
.printOnly {
margin-top: 100px;
display: none;
}
.textSummaryTable { page-break-inside:auto }
.textSummaryTable tr { page-break-inside:avoid; page-break-after:auto }
#media print {
.summaryTable tr:nth-child(odd){ background-color:#E1E4E5;}
.summaryTable tr:nth-child(even) { background-color:#ffffff; }
.printOnly { display: block; }
.panel {
border: 1px solid transparent;
padding: 2px;
margin: 0;
}
.textSummaryTable{ border:1px solid gray; }
.textSummaryTable td{ border:1px solid gray; }
#main {
overflow: hidden;
position: absolute;
padding: 0px;
height: auto;
width: 100%;
}
#title { display: none; }
#line-break { display: block; }
.textSummaryTable { width: 100%; }
}
#media screen {
#line-break { display: none; }
}
</style>
and My tables are here.
<?php
$this->pageTitle = Yii::app()->name . ' - View Evaluation';
$user = LoginForm::getUser();
?>
<?php $participants = $modelE->evaluationDetails; ?>
<style type="text/css">
#media print {
body {
overflow: hidden;
}
}
</style>
<div class=" non-printable">
<div class='pull-right non-printable'>
<button id="btnPrint" type="button" class="btn btn-default pull-right" onclick="window.print();">
<span class="glyphicon glyphicon-print"></span> Print
</button>
</div>
<?php
$startDate = date("M j, Y", strtotime($modelE->start_date));
$endDate = date("M j, Y", strtotime($modelE->end_date));
?>
</div>
<div id='line-break'>
<br>
<br>
<br>
</div>
<div class="container-fluid">
<div class="printable">
<h4><?php echo htmlentities($modelE->evaluationForm->name); ?></h4>
<h5><?php echo $startDate; ?> - <?php echo $endDate; ?></h5>
<h5>Candidate: <?php echo htmlentities($modelE->evaluatee); ?></h5>
<h5>Overall Evaluation: <?php echo htmlentities($modelE->getResult()); ?></h5>
<h5>Participants: <?php echo htmlentities(count($participants)); ?></h5>
<div class="panel panel-default">
<div class="panel-body">
<h5><strong>Instructions: </strong> <?php echo htmlentities($modelE->evaluationForm->description); ?></h5>
<!-- <h4>Results Summary</h4> -->
<?php
$radioFlag = false;
foreach ($modelE->evaluationForm->evaluationFormDetails as $question) {
$criteria = new CDbCriteria;
$criteria->with = 'evalResult';
$criteria->addInCondition('eval_form_question_id', array($question->id));
$criteria->addInCondition('evalResult.eval_id', array($modelE->id));
$resultSet = EvaluationResultsDetails::model()->findAll($criteria);
if ( strtolower($question->field_type) != "radioheader" && $question->field_type != "slider" ) {
if($radioFlag){
echo "</table>";
$radioFlag = false;
}
if( $question->field_type == "text" ) {
echo "<h4>" . $question->field_name . "</h4>";
}
else {
echo "<table class='textSummaryTable'><tr><td style='width: 100%'><label>" . $question->field_name . "</label></td></tr>";
foreach ($resultSet as $answer) {
echo "<tr><td>" . $answer->eval_answer . "</td></tr>";
}
echo "</table>";
}
} else {
if(!$radioFlag){
echo '<table border-size = 0px width=100% class="summaryTable">';
$radioFlag = true;
}
echo "<tr><td style='width: 90%'>" . $question->field_name . "";
echo "</td><td style='width: 10%'>";
$sum = 0;
$count = 0;
foreach ($resultSet as $answer) {
$count++;
$sum += $answer->eval_answer;
}
echo $count == 0 ? "-" : number_format($sum / $count, 2);
echo "</td></tr>";
/*** end here ***/
}
}
if($radioFlag){
echo "</table>";
}
?>
<table class="printOnly">
<tr>
<td colspan="2">
<p> I hereby certify that all information declared in this document are accurate and true. Each item have been discussed with my Immediate Superior and mutually agreed upon.</p>
</td>
</tr>
<tr>
<td>
<p>Prepared by
<?= $modelE->project->manager->family_name . ", " . $modelE->project->manager->first_name ?>
</p>
Date <?= date("Y-m-d"); ?>
</td>
<td>
<p>Conformed by <?= $modelE->evaluatee ?></p>
Date
</td>
</tr>
<tr>
<td colspan="2">
<p>Noted by HR Division</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
It's me again, sorry...
I've been looking for the answer right in this forums, but there are no posts has been solved. I don't know if the questioner has been resolved the problems and not given a solved comment or something like that. All the comments/replies from the questioner is 'not work' or 'get some new errors' ect.
Now my scripts has worked before I put pagination scripts on them, but again errors in 'mysqli'. The errors are:
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\paging\index.php on line 8
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\paging\index.php on line 9
My scripts contained two files:
index.php:
<?php
$con = mysqli_connect("localhost", "root", "", "db_book") or die(mysqli_error($con));
$per_page = 3;
//getting number of rows and calculating no of pages
$sql = "SELECT COUNT(*) FROM flipbook";
$result = mysqli_query($sql);
$count = mysqli_fetch_row($result);
$pages = ceil($count[0]/$per_page);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>DIGITAL LIBRARY</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" src="pagination.js"></script>
<style>
body { margin: 0; padding: 0; font-family:Verdana; font-size:15px }
a
{
text-decoration:none;
color:#B2b2b2;
}
a:hover
{
color:#DF3D82;
text-decoration:underline;
}
#loading {
width: 100%;
position: absolute;
}
#pagination
{
text-align:center;
margin-left:120px;
}
li{
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #dddddd;
color:#0063DC;
}
li:hover
{
color:#FF0084;
cursor: pointer;
}
</style>
</head>
<body>
<div align="center">
<div style="margin-top:50px;"></div>
<div id="content" ></div>
<table width="800px">
<tr><Td>
<ul id="pagination">
<?php
//Show page links
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
</ul>
</Td>
</tr></table>
<div id="loading" ></div>
</div>
</body>
</html>
and data.php:
<?php
$con = mysqli_connect("localhost", "root", "", "db_book");
$sql = mysqli_query($con,"SELECT b.*, title, author_name, url_flipbook, p.publisher_name, ct.cat_name FROM biblioflip AS b
LEFT JOIN mst_publisherflip AS p ON b.publisher_id=p.publisher_id
LEFT JOIN mst_catflip AS ct ON b.cat_id=ct.cat_id
ORDER BY flip_id limit $start,$per_page") or die(mysqli_error($con));
$per_page = 3;
if($_GET)
{
$page=$_GET['page'];
}
//getting table contents
$start = ($page-1)*$per_page;
?>
<table id="tbl">
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Category</th>
<th>Link</th>
<?php
while($row = mysqli_fetch_array($result))
{
$title = $row['title'];
$author = $row['author_name'];
$publisher = $row['publisher_name'];
$category = $row['cat_name'];
$link = 'FLIPBOOK</td>';
?>
<tr>
<td><?php echo $title; ?></td>
<td><?php echo $author; ?></td>
<td><?php echo $publisher; ?></td>
<td><?php echo $category; ?></td>
<td><?php echo $link; ?></td>
</tr>
<?php
} //End while
mysqli_close($con);
?>
</table>
<style>
#tbl
{
width:800px;
border:1px solid #98bf21;
margin-top:50px;
}
#tbl tr:nth-child(odd) {
background: #EAF2D3
}
#tbl td{
border:1px solid #98bf21
}
#tbl th
{
background: #A7C942;
border:1px solid #98bf21
}
</style>
Thanks again...thank you...
best regards,
The error message is quite descriptive and clear: The first parameter to mysqli_query should be the connection handle.
Instead of $result = mysqli_query($sql);, use $result = mysqli_query($con, $sql);
Overview
I have some data stored in MySql database related to Products. I am trying to retrieve this data and display it on a page using HTML table.
The PHP and MySql has gone well and all the data is retrieved but it is displayed in a very messy manner.
Here is what I have as a layout:
What I am aiming to achieve is to further divide the results table add more columns rows to make the data more readable
Something like this;
The code: PHP, MySQL & HTML:
<?php
session_start();
include('connect_mysql.php');
$product_name = 'product_name';
$product_qua = 'product_qua';
$product_price = 'product_price';
$product_image = 'product_image';
$product_des = 'product_des';
$sql = mysql_query("SELECT * FROM products");
echo "<table id='display'>";
while($rows = mysql_fetch_array($sql))
{
echo"<br>";
echo"<tr><td>";
echo"$rows[$product_name]<br></td>";
echo"<td><img src=$rows[$product_image] height='200px' width='200px'><br></td>";
echo"<td>Avalible: $rows[$product_qua]<br></td>";
echo"<td>Price: $rows[$product_price]<br></td>";
echo"<td>Description: $rows[$product_des]<br></td>";
echo"</tr>";
}
echo "</table>";
?>
CSS responsible for this part:
#display{
float:left;
border: 5px solid black;
margin-left:100px;
}
just add some padding or a border to the table cells:
table#display td{
border: 1px solid black;
padding:0 8px;
}
Edit: What you could do as well:
<table id='display'>
<?php while($rows = mysql_fetch_array($sql)): ?>
<!-- <br> <- why a break? it's not in the correct spot anyway -->
<tr><td>
<?php echo $rows[$product_name]; ?><br>
</td>
<td> - </td>
<td><img src="<?php echo $rows[$product_image]; ?>" height='200px' width='200px'><br></td>
<td> - </td>
<td>Avalible: <?php echo $rows[$product_qua]; ?><br></td>
<td> - </td>
<td>Price: <?php echo $rows[$product_price]; ?><br></td>
<td> - </td>
<td>Description: <?php echo $rows[$product_des]; ?><br></td>
</tr>
<?php endwhile; ?>
</table>
Tip: I prefer to use the while/endwhile; approach rather than using brackets when displaying data to the user.
First of all don't echo so much HTML using PHP, instead do it like this
<?php
session_start();
include('connect_mysql.php');
$product_name = 'product_name';
$product_qua = 'product_qua';
$product_price = 'product_price';
$product_image = 'product_image';
$product_des = 'product_des';
$sql = mysql_query("SELECT * FROM products"); ?>
<table id='display'>
<?php
while($rows = mysql_fetch_array($sql)) {
?>
<tr><td><?php echo $rows[$product_name]; ?></td>
<!-- And so on-->
<?php
}
?>
</table>
Secondly by seeing your inmage, it seems like you need a border for your table so use
table, td {
border: 1px solid #000000;
}
add the following css to apply border on your table cells:
#display td{ border: 2px solid red; }
and optionally add to your #display { :
border-collapse: collapse;