Jump to content
php.lv forumi

2x2


Chickenz

Recommended Posts

Man taads jautaajums, kaa lai zinjas tiek izdrukaatas 2x2 tabulaa???

Negribas divus ciklus likt...

ir kaadi padomi, kaa vareetu ar vienu ciklu no db atlasiit 4 ieraxtus un samest 2x2 tabulaa???

 

ps. raxtiiju shito topicu tikai tapeec ka vecajam news neviens nepieveersh uzmaniibu...

Link to comment
Share on other sites

Padomā par kaut ko līdzīgu šim:

$news = array('news1' , 'news2', ' news3' , 'news4');
$newsId = 0;
echo '<table><tr>';
foreach ($news as $newsItem){
  echo '<td>' . $newsItem . '</td>';
  if ($newsId % 2 == 0 && $newsId < count($news) - 1){
     echo '</tr><tr>';
  }
}
if ($newsId % 2 != 0){
echo '<td> </td>';
}
echo '</tr></table>';

Link to comment
Share on other sites

Nu bāc!

<?php
 $res = mysql_query('SELECT teksts FROM news LIMIT 4');
 $rows = array();
 while ($temp = mysql_fetch_row($res)) {
   $rows = $temp[0];
 }
 while (count($rows)<4) { $rows[] = ""; }
 echo '<table>';
 echo '<tr><td>'.$rows[0].'</td><td>'.$rows[1].'</td></tr>';
 echo '<tr><td>'.$rows[2].'</td><td>'.$rows[3].'</td></tr>';
 echo '</table>';
?>

Kaklz pasteidzās :)

Edited by bubu
Link to comment
Share on other sites

NB: bubu $rows[] = $temp[0];

 

ziņas, kas izvadās Z veidā

$pahorizontali=2;

echo '<table><tr>';

$tmp=0;

while($res=mysql_fetch_array(...))

{

echo '<td>'.$res['news'].'</td>';

if (++$tmp%$pahorizontali=0)

echo '</tr><tr>';

}

echo '</tr></table>';

 

ziņas izvadās И veidā:

 

$pavertikali=2;

echo '<div style="float:left">';

$tmp=0;

while($res=mysql_fetch_array(...))

{

echo '<div class="newsblock">'.$res['news'].'</div>';

if (++$tmp%$paveritkali=0)

echo '</div><div style="float:left">';

}

echo '</div>';

Link to comment
Share on other sites

×
×
  • Create New...