Который из этих лучше?
1
2
3
4
5
6
AND
1 / 2
3 / 4
5 / 6
AND
1 / 2 / 3
4 / 5 / 6
AND
1 / 2 / 3 / 4
5 / 6 / 7 / 8
9/ 10/ 11/12
В этих примерах slash = class=\"Boxright\" (пунткированная линия на правой стороне в каринке). Насколько радикально надо менять код?
Код:
<?
$data = true;
while ( $data ) {
echo "<tr>";
$cols = 3;
while ( ($data = mysql_fetch_array($result)) && $cols-- ){
echo "<td>";
echo $data['col1'] . "
";
echo $data['col2'] . "
";
// т.д.
echo "</td>";
}
while ( $cols-- ){
echo "<td></td>";
}
echo "</tr>";
}
?>
////
\$link = mysql_connect(\$HOST, \$USER, \$PASS) or die("Could not connect");
mysql_select_db(\$db_name) or die("Could not select database");
?>
<table>
<?
$cols = 2;
$query = "SELECT * FROM table ORDER BY name";
if(!$result = mysql_query($query)) echo "Query failed";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data = $line[name];
if ($i == 0)
{
echo "<tr>";
}
if ($i == 2)
{
echo "</tr><tr>";
$i = 0;
}
echo "<td>\$data</td>";
$i++;
}
if ($i != 2) echo "</tr>";
?>
</table>
///
<?php
$val = array(1,2,3,4,5,6,7,8,9,10);
$col = 2;
$numVal = count($val);
?>
<table border=1>
<?php
$rows = ceil($numVal/$col);
for($i = 1; $i <= $rows;$i++) {
echo ' <tr>';
for($n=1; $n <= $col; $n++) {
if($i == $rows) {
if(($i-1)*$col+$n == $numVal) {
$colspan = ' colspan="'.$rows * $col - $numVal + 1 .'"';
}
}
echo '<td>'.$val[($i-1)*$col+$n-1]."</td>\\n";
}
echo '</tr>';
}
?>
</table>
////
<?
$sql="SELECT * FROM pic";
$result = mysql_query($sql);
while($data=mysql_fetch_array($result)) {
if (!(++$i % $cols)) echo '<tr>';
echo "<td>", $data['content'], "</td>";
if (!($i % $cols)) echo '</tr>';
}
if (($i % $cols)) {
while (++$i % $cols) echo "<td></td>\\n"
echo '</tr>\\n';
}
?>
////
<?
while (1) {
echo "<tr>";
for ($i = 0; $i<$cols; $i++) {
echo "<td>";
if ($data=mysql_fetch_array($result))) {
echo $data['content'];
} else echo "";
echo "</td>";
}
echo "</tr>";
if (!$data) break;
}
?>
$data = true;
while ( $data ) {
echo "<tr>";
$cols = 3;
while ( ($data = mysql_fetch_array($result)) && $cols-- ){
echo "<td>";
echo $data['col1'] . "
";
echo $data['col2'] . "
";
// т.д.
echo "</td>";
}
while ( $cols-- ){
echo "<td></td>";
}
echo "</tr>";
}
?>
////
\$link = mysql_connect(\$HOST, \$USER, \$PASS) or die("Could not connect");
mysql_select_db(\$db_name) or die("Could not select database");
?>
<table>
<?
$cols = 2;
$query = "SELECT * FROM table ORDER BY name";
if(!$result = mysql_query($query)) echo "Query failed";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data = $line[name];
if ($i == 0)
{
echo "<tr>";
}
if ($i == 2)
{
echo "</tr><tr>";
$i = 0;
}
echo "<td>\$data</td>";
$i++;
}
if ($i != 2) echo "</tr>";
?>
</table>
///
<?php
$val = array(1,2,3,4,5,6,7,8,9,10);
$col = 2;
$numVal = count($val);
?>
<table border=1>
<?php
$rows = ceil($numVal/$col);
for($i = 1; $i <= $rows;$i++) {
echo ' <tr>';
for($n=1; $n <= $col; $n++) {
if($i == $rows) {
if(($i-1)*$col+$n == $numVal) {
$colspan = ' colspan="'.$rows * $col - $numVal + 1 .'"';
}
}
echo '<td>'.$val[($i-1)*$col+$n-1]."</td>\\n";
}
echo '</tr>';
}
?>
</table>
////
<?
$sql="SELECT * FROM pic";
$result = mysql_query($sql);
while($data=mysql_fetch_array($result)) {
if (!(++$i % $cols)) echo '<tr>';
echo "<td>", $data['content'], "</td>";
if (!($i % $cols)) echo '</tr>';
}
if (($i % $cols)) {
while (++$i % $cols) echo "<td></td>\\n"
echo '</tr>\\n';
}
?>
////
<?
while (1) {
echo "<tr>";
for ($i = 0; $i<$cols; $i++) {
echo "<td>";
if ($data=mysql_fetch_array($result))) {
echo $data['content'];
} else echo "";
echo "</td>";
}
echo "</tr>";
if (!$data) break;
}
?>