Kann mir jemand helfen? Ich möchte aus einer SQL-Tabelle die Daten auslesen und zwar so, dass diese nicht alle untereinander sondern zweizeilig erscheinen.
News in 2 Spalten
Collapse
X
-
PHP Code:// dein resultset
$aRecordSets = array(1, 1, 1, 1, 1, 1, 1);
$i = 1;
while ( $aSet = array_shift($aRecordSets) )
{
if ( $i == 1 )
{
?>
<table>
<tr>
<?
}
?>
<td><?=$i?></td>
<?
if ( ($i%2) == 0 )
{
if ( sizeof($aRecordSets) > 0 )
{
?>
</tr>
<tr>
<?
}
else
{
?>
</tr>
</table>
<?
}
}
if ( sizeof($aRecordSets) == 0 && ($i%2) != 0 )
{
?>
</tr>
</table>
<?
}
$i++;
}Last edited by reallife; 29-04-2006, 09:46.
Comment
-
-
array_chunk()
PHP Code:<?php
$temp = array('d1', 'd2','d3','d4','d5');
$split = 2;
// Das Array Teilen.
$sor_temp = array_chunk($temp, $split);
//Ausgabe
foreach($sor_temp as $_temp) {
foreach($_temp as $c) {
echo $c;
}
echo '<br>';
}
?>
gruss
Shin Yoshida
Comment
-
da es sich sowieso um eine sql-abfrage handelt, sehe ich kein Sinn das ganze erst in ein array zu packen, um später diesen wieder durchlaufen.
aus diesem Grund hat zonthor meine Meinung nach, das beste und schnellste Variante vorgeschlagenSlava
bituniverse.com
Comment
-
@zonthor
wenn duPHP Code:$i = 0;
PHP Code:$i = 1;
Und weil es so schön ist hier noch ne Lösung
PHP Code:echo '<table width="150" align="center">';
$max = 4; // Anzahl der Ausgaben pro Zeile
$i = 1;
while ($row = mysql_fetch_array($sql))
{
if ($i == 1)
echo '<tr>';
echo '<td>'.row[id].'</td>';
if ($i == $max)
{
echo '</tr>';
$i = 1;
} else $i++;
}
Sers
Der Boris
Comment
Comment