Четные и нечетные стр.
Пояcню на примере: ( $cols = "2" ) 1 / 2
( $cols = "3" ) 1 / 2 / 3. Я понимаю, что то, что я нписал это не хорошо, но оно, по краянее мере работает. Его можно сокаратить, сохраняя функциональность?
Код:
<?
$cols = "2"; // 2 row mode
$query = "SELECT * FROM imglib WHERE cat='\$c' ORDER BY \$so \$o LIMIT \$initialPhoto, \$it";
if(!$result = mysql_query($query)) echo "Query failed";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data = $row["url"];
if ($i == 0) {
echo "<tr>"; }
if (($i % $cols) == 0 ) { // if (\$i == \$cols)
echo "</tr><tr>";
echo "<tr>";
echo "<td width=\"540\" height=\"30\" colspan=\"2\" class=\"BoxBellow\">";
echo "
</p>";
echo "</td>";
echo "</tr>";
$i = 0; }
if ((1&$i)) { // odd shows no dotted line
echo "<td width=\"270\">";
}
if (!(1&$i)) { // even shows a dotted line
echo "<td width=\"270\" class=\"Boxright\">"; }
itemplaceholder(); //common
echo "</td>"; //common
$i++; }
if ($i != $cols)
echo "</tr>";?>
$cols = "2"; // 2 row mode
$query = "SELECT * FROM imglib WHERE cat='\$c' ORDER BY \$so \$o LIMIT \$initialPhoto, \$it";
if(!$result = mysql_query($query)) echo "Query failed";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data = $row["url"];
if ($i == 0) {
echo "<tr>"; }
if (($i % $cols) == 0 ) { // if (\$i == \$cols)
echo "</tr><tr>";
echo "<tr>";
echo "<td width=\"540\" height=\"30\" colspan=\"2\" class=\"BoxBellow\">";
echo "
</p>";
echo "</td>";
echo "</tr>";
$i = 0; }
if ((1&$i)) { // odd shows no dotted line
echo "<td width=\"270\">";
}
if (!(1&$i)) { // even shows a dotted line
echo "<td width=\"270\" class=\"Boxright\">"; }
itemplaceholder(); //common
echo "</td>"; //common
$i++; }
if ($i != $cols)
echo "</tr>";?>
$tr = ($i % 2) ? $val1 : $val2;
ДМС ПРТЕДЕМЕОЙС ЮЕФОЩИ Й ОЕЮЕФОЩИ ЪОБЮЕОЙК $i
$tr = ($i % 2) ? $val1 : $val2;
ДМС ПРТЕДЕМЕОЙС ЮЕФОЩИ Й ОЕЮЕФОЩИ ЪОБЮЕОЙК $i
Цитата:
Originally posted by pavluk
рПРТПВХК
$tr = ($i % 2) ? $val1 : $val2;
ДМС ПРТЕДЕМЕОЙС ЮЕФОЩИ Й ОЕЮЕФОЩИ ЪОБЮЕОЙК $i
рПРТПВХК
$tr = ($i % 2) ? $val1 : $val2;
ДМС ПРТЕДЕМЕОЙС ЮЕФОЩИ Й ОЕЮЕФОЩИ ЪОБЮЕОЙК $i
А так?
Код:
/* What cool parameter names... */
function display_gallery($c, $so, $o, $initialPhoto, $columns, $lines)
{
/* Prepare the query line */
$query = 'SELECT * FROM imglib WHERE cat="'.$c.'" ORDER BY '.$so.' '.$o.' LIMIT '.$initialPhoto.', '.($columns*$lines);
/* Execute query */
if(!$result = mysql_query($query))
{
echo 'Query failed'
return();
}
/* Add one column for the empty cell */
$columns++;
/* Loop over the result to display it */
$columnIndex = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
/* Is it a new line? */
if ($columnIndex % $columns)
{
echo '<tr>';
}
/* If first cell of the line, then put an empty cell */
if (!$columnIndex)
{
echo '<td width="540" height="30" colspan="2" class="BoxBellow">
</p></td>';
}
/* If not open a cell*/
else
{
if ($columnIndex % 1)
{
// odd shows no dotted line
echo '<td width="270">';
}
else
{
// even shows a dotted line
echo '<td width="270" class="Boxright">';
}
}
/*
Insert the pics or whatever this function is doing...
But i guess that somehow, you should use $row['url'] as
parameter
*/
itemplaceholder();
/* Close the cell */
echo '</td>';
/* Increment counter */
$columnIndex = ($columnIndex + 1) % $columns;
/* Is it end of line? */
if (!$columnIndex)
{
echo '</tr>';
}
}
/*
After looping, It is way unsure to assume that
all line have the same amount of cells. Therefore,
we are fixing the next line to be good.
And closing line as well if needed.
*/
if ($columnIndex)
{
echo '<td colspan='.($columns-$columnIndex).'></td></tr>';
}
}
function display_gallery($c, $so, $o, $initialPhoto, $columns, $lines)
{
/* Prepare the query line */
$query = 'SELECT * FROM imglib WHERE cat="'.$c.'" ORDER BY '.$so.' '.$o.' LIMIT '.$initialPhoto.', '.($columns*$lines);
/* Execute query */
if(!$result = mysql_query($query))
{
echo 'Query failed'
return();
}
/* Add one column for the empty cell */
$columns++;
/* Loop over the result to display it */
$columnIndex = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
/* Is it a new line? */
if ($columnIndex % $columns)
{
echo '<tr>';
}
/* If first cell of the line, then put an empty cell */
if (!$columnIndex)
{
echo '<td width="540" height="30" colspan="2" class="BoxBellow">
</p></td>';
}
/* If not open a cell*/
else
{
if ($columnIndex % 1)
{
// odd shows no dotted line
echo '<td width="270">';
}
else
{
// even shows a dotted line
echo '<td width="270" class="Boxright">';
}
}
/*
Insert the pics or whatever this function is doing...
But i guess that somehow, you should use $row['url'] as
parameter
*/
itemplaceholder();
/* Close the cell */
echo '</td>';
/* Increment counter */
$columnIndex = ($columnIndex + 1) % $columns;
/* Is it end of line? */
if (!$columnIndex)
{
echo '</tr>';
}
}
/*
After looping, It is way unsure to assume that
all line have the same amount of cells. Therefore,
we are fixing the next line to be good.
And closing line as well if needed.
*/
if ($columnIndex)
{
echo '<td colspan='.($columns-$columnIndex).'></td></tr>';
}
}