<?php
$dbhost = 'localhost';
$dbuser = '/////////';
$dbpass = '////////';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = '///////';
mysql_select_db($dbname);
mysql_query("SET NAMES 'utf8'", $conn);
$result = mysql_query($query);
$query = "SELECT * FROM 3orod";
$result = mysql_query($query);
$i= 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="rtl" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="ar-sa" http-equiv="Content-Language" />
<title>آخر العروض</title>
<style type="text/css">
body {
width: 99%;
margin-left:auto;
margin-right:auto;
background-color: gray;
color: #505050;
}
.website {
background-color: #FFFFFF;
border:1px solid #000000;
border-radius: 10px;
min-width:860px;
box-shadow: 5px 5px 5px #000000;
max-height: 99%;
min-height: 600;
height: 99%;
}
.header {
background-color: #E6F3DB;
font-size:small;
font-style:oblique;
}
.header2 {
background-color: #E6F3DB;
font-size:small;
font-style:oblique;
}
.row {
background-color: #FFFFFF;
font-size:small;
font-style:oblique;
}
table {
border:1px solid #000000;
max-width:99%;
}
td {
}
</style>
</head>
<body>
<div class="website">
<table width="100%" border="1">
<?php
while($row = mysql_fetch_assoc($result))
{
if ($i == 0){
echo "<tr>".
"<td class='header'> {$row['A']}</td>".
"<td width='3%' class='header'> {$row['B']}</td>".
"<td class='header'> {$row['C']}</td>".
"<td class='header'> {$row['D']}</td>".
"<td class='header'> {$row['E']}</td>".
"<td class='header'> {$row['F']}</td>".
"<td class='header'> {$row['G']}</td>".
"<td class='header'> {$row['H']}</td>".
"<td class='header2'> {$row['I']}</td>".
"<td width='1px' class='header'> {$row['J']}</td>".
"<td width='1px' class='header'> {$row['K']}</td>".
"<td class='header'> {$row['L']}</td>".
"<td class='header'> {$row['M']}</td>".
"<td class='header'> {$row['N']}</td>".
"<td class='header'> {$row['O']}</td>".
"<td class='header'> {$row['P']}</td>".
"<td class='header'> {$row['Q']}</td>".
"<td class='header'> {$row['R']}</td>".
"<td class='header'> {$row['S']}</td>".
"<td class='header'> {$row['T']}</td>".
"<td class='header'> {$row['U']}</td>".
"<td class='header'> {$row['V']}</td>".
"<td class='header'> {$row['W']}</td>".
"<td class='header'> {$row['X']}</td>".
"<td class='header'> {$row['Y']}</td>".
"<td class='header'> {$row['Z']}</td>".
"</tr>" ;
$i=1;
}
else
{
echo "<tr>".
"<td class='row'> {$row['A']}</td>".
"<td width='3%' class='row'> {$row['B']}</td>".
"<td class='row'> {$row['C']}</td>".
"<td class='row'> {$row['D']}</td>".
"<td class='row'> {$row['E']}</td>".
"<td class='row'> {$row['F']}</td>".
"<td class='row'> {$row['G']}</td>".
"<td class='row'> {$row['H']}</td>".
"<td class='row2'> {$row['I']}</td>".
"<td width='1px' class='row'> {$row['J']}</td>".
"<td width='1px' class='row'> {$row['K']}</td>".
"<td class='row'> {$row['L']}</td>".
"<td class='row'> {$row['M']}</td>".
"<td class='row'> {$row['N']}</td>".
"<td class='row'> {$row['O']}</td>".
"<td class='row'> {$row['P']}</td>".
"<td class='row'> {$row['Q']}</td>".
"<td class='row'> {$row['R']}</td>".
"<td class='row'> {$row['S']}</td>".
"<td class='row'> {$row['T']}</td>".
"<td class='row'> {$row['U']}</td>".
"<td class='row'> {$row['V']}</td>".
"<td class='row'> {$row['W']}</td>".
"<td class='row'> {$row['X']}</td>".
"<td class='row'> {$row['Y']}</td>".
"<td class='row'> {$row['Z']}</td>".
"</tr>" ;
}
}
mysql_close();
?>
</table>
</div>
</body>
</html>
if you see the results you can see that the cells expanding with no reason
http://www.almousaakar.com/test/3orod/admin/
my regards
The cells aren’t expanding for no reason, they’re expanding to fit the cell contents. Take a look at automatic table layout. Also, the HTML4 spec says about table cell width:
It’s bad form both to link to an enormous page as a sample and to link to an enormous page without warning. Some browsers might misbehave, and people won’t appreciate you crashing their browser. Samples (both pages and code) should be concise and complete. Remove anything extraneous, both from sample code and by reducing the results displayed.
Off-Topic
For header cells, use
<th>, not<td>with a class. Keep it semantic.If you find yourself repeating code, you should be using a function or a loop.
The mysql extension is on its way to deprecation. Use PDO or mysqli, both of which support prepared statements.
Hopefully, you’re not putting the database credentials in the main script as you do in the sample. Sensitive information should be kept in a single location, where it’s easier to secure. Also, the more you repeat something, the greater chance for a typo. Don’t repeat yourself.
Names should be descriptive; single letter column (or variable or …) names aren’t. They’ve even been part of a daily WTF. Hopefully, this is just in the sample code and the production code (and database) has more descriptive names.
Style sheets are preferred over the
widthattribute for setting table cell width, as a consequence of separation of structure from presentation. You can give cells a class to target in selectors; when they have broader browser support, you can use:nth-child()or:nth-of-type()pseudo-classes in selectors (e.g.tr > nth-child(2),th:nth-of-type(2), td:nth-of-type(2)) rather than classes. From the same section of the HTML4 spec that was previously linked to:Here’s an example that incorporates changes for some of these issues. First, ‘localdb.php’, a class that handles DB connection creation and lets you isolate credentials somewhere (though where isn’t shown). Note that it still has problems (such as data access and presentation are too closely coupled).
Next, the main script (without the embedded style sheet, since that doesn’t matter in the example and should, in any case, be placed in an external style sheet):