Archivlink: javarea.de Forum > PHP, MySQL & CGI > richtig auflisten
Vollständigen Link anzeigen: javarea.de Forum > PHP, MySQL & CGI > richtig auflisten

Pages: [1]

geschrieben von rich am 25.01.2010 - 22:51
hey ich bins mal wieder =)
ich hab mal wieder was für euch und zwar hab ich eine auflistung von Bildern und Titeln
die aus der DB geladen werden...

PHP-Quelltext
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="0" cellspacing="0" cellpadding="1">


<?php
$sql
="SELECT * FROM ".$prefix."spiele WHERE kategorie IN ('Action') order by spielname";
$result=mysql_query($sql);

while(
$rows=mysql_fetch_array($result)){
?>
<tr>
<td><A class=flyout href="<? echo $rows[gamelogo]; ?>"><img class=tmbright src="<? echo $rows[gamelogo]; ?>" width="80" height="80" alt="" border="0"></a></td>
<td><a href="game.php?id=<? echo $rows['spiele_id']; ?>"><font size="2"><? echo $rows['spielname']; ?></font></a></td>
<td><font size="2"><? echo $rows['genre']; ?></font></td>
<!-- <td><? echo $rows['kategorie']; ?></td> -->
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>



jetzt wird das alles untereinander ausgegeben....

Bild -> ($rows[gamelogo]; )
Title -> (echo $rows['spiele_id'];)
kategorie -> (echo $rows['genre'];)

zur zeit wird dies noch Alphabetisch nach Kategorie so ausgegeben...

Bild 1 ($rows[gamelogo]; ) - Title (echo $rows['spiele_id'];) - kategorie (echo $rows['genre'];)
Bild 2 ($rows[gamelogo]; ) - Title (echo $rows['spiele_id'];) - kategorie (echo $rows['genre'];)
Bild 3 ($rows[gamelogo]; ) - Title (echo $rows['spiele_id'];) - kategorie (echo $rows['genre'];)
usw usw usw....

ich möchte aber, dass dies in 2 reihen ausgegeben wird
in etwa so...

Bild 1 - Title - Kategorie | Bild 2 - Title - Kategorie
Bild 3 - Title - Kategorie | Bild 4 - Title - Kategorie
Bild 5 - Title - Kategorie | Bild 6 - Title - Kategorie

usw... =)
kann man doch sicherlich mit einer Schleife machen oder ?!
mfg rich

geschrieben von Micha am 26.01.2010 - 08:03
Hi,

Du musst nur die öffnenden und schließenden TRs korrekt in Deiner while-Schleife setzen. Ich würde hier bspw. mit einer Zählvariablen und Modular arbeiten.

HTML-Quelltext
1: 
2: 
3: 
4: 
5: 
6: 
7: 
$i=0;
while($rows=mysql_fetch_array($result)){
  echo "<td> ... </td>";
  if (i%2==0)
    echo "</tr><tr>";
  $i++;
}


Gruß Micha

geschrieben von rich am 26.01.2010 - 11:02
hey Micha...
ja genau so eine schleife meinte ich...
dein beisp. funktioniert leider nicht wie gewünscht

hier noch ein wenig mehr quelltext


PHP-Quelltext
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
90: 
91: 
92: 
93: 
94: 
95: 

<?
include("include/logincheck.php");
include(
"include/config.php");
include(
"include/db.php");

?>

<!--
Start Block Anfang
Start Action
-->
<table border="0" cellpadding="0" cellspacing="0" width="95%" align="center" height="25" background="<? echo $basedir?>images/fon_bar01.gif">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" background="" bgcolor="#FFFFFF">
<tr>
<td><img src="<? echo $basedir?>images/e03.gif" width="21" height="21" alt="" border="0" align="left"></td>
<td><p class="bar01" style="color: #DA0008; font-size: 18px;">Action</p></td>
</tr>
</table>
</td>
</tr>
</table>
<!--
Ende Überschrift1
-->
<table border="0" cellpadding="3" cellspacing="0" align="center">
<tr valign="top">
<td>
<!-- left -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><img src="<? echo $basedir?>images/t_11.gif" width="10" height="9" alt="" border="0"></td>
<td background="<? echo $basedir?>images/t_13.gif"><img src="<? echo $basedir?>images/t_12.gif" width="6" height="9" alt="" border="0"></td>
<td background="<? echo $basedir?>images/t_13.gif" align="right"><img src="<? echo $basedir?>images/t_14.gif" width="6" height="9" alt="" border="0"></td>
<td><img src="<? echo $basedir?>images/t_15.gif" width="10" height="9" alt="" border="0"></td>
</tr>
<tr valign="top">
<td background="<? echo $basedir?>images/t_fon_left.gif"><img src="<? echo $basedir?>images/t_21.gif" width="10" height="6" alt="" border="0"></td>
<td rowspan="2" colspan="2">


<!--
Start Zelle1 Block Anfang
-->
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="0" cellspacing="0" cellpadding="1">


<?php
$sql
="SELECT * FROM ".$prefix."spiele WHERE kategorie IN ('Action') order by spielname";
$result=mysql_query($sql);

while(
$rows=mysql_fetch_array($result)){
?>
<tr>
<td><A class=flyout href="<? echo $rows[gamelogo]; ?>"><img class=tmbright src="<? echo $rows[gamelogo]; ?>" width="80" height="80" alt="" border="0"></a></td>
<td><a href="game.php?id=<? echo $rows['spiele_id']; ?>"><font size="2"><? echo $rows['spielname']; ?></font></a></td>
<td><font size="2"><? echo $rows['genre']; ?></font></td>
<!-- <td><? echo $rows['kathegorie']; ?></td> -->
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>

</td>
<td background="<? echo $basedir?>images/t_fon_right.gif"><img src="<? echo $basedir?>images/t_23.gif" width="10" height="6" alt="" border="0"></td>
</tr>
<tr valign="bottom">
<td background="<? echo $basedir?>images/t_fon_left.gif"><img src="<? echo $basedir?>images/t_31.gif" width="10" height="7" alt="" border="0"></td>
<td background="<? echo $basedir?>images/t_fon_right.gif"><img src="<? echo $basedir?>images/t_33.gif" width="10" height="7" alt="" border="0"></td>
</tr>
<tr>
<td><img src="<? echo $basedir?>images/t_41.gif" width="10" height="10" alt="" border="0"></td>
<td background="<? echo $basedir?>images/t_fon_bot.gif"><img src="<? echo $basedir?>images/t_42.gif" width="6" height="10" alt="" border="0"></td>
<td background="<? echo $basedir?>images/t_fon_bot.gif" align="right"><img src="<? echo $basedir?>images/t_44.gif" width="6" height="10" alt="" border="0"></td>
<td ><img src="<? echo $basedir?>images/t_45.gif" width="10" height="10" alt="" border="0"></td>
</tr>
</table>
<!-- /left -->
</td>
</tr>
</table>
<!--
Ende Block Anfang
Ende Action
-->



vielleicht hilft das ja ein wenig mehr =)
danke.

geschrieben von rich am 27.01.2010 - 18:18
ach ich verwende PHP5...
vielleicht is das ja noch wichtig.

geschrieben von Danny am 28.01.2010 - 11:46
Das Beispiel von Micha sollte vom Prinzip her funktionieren.
so in der Art

HTML-Quelltext
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
<table>
<tr>


<?php
$i = 1;
while($rows=mysql_fetch_array($result)){
?>
<td><A class=flyout href="<? echo $rows[gamelogo]; ?>"><img class=tmbright src="<? echo $rows[gamelogo]; ?>" width="80" height="80" alt="" border="0"></a></td>
<td><a href="game.php?id=<? echo $rows['spiele_id']; ?>"><font size="2"><? echo $rows['spielname']; ?></font></a></td>
<td><font size="2"><? echo $rows['genre']; ?></font></td>

<?php if($i%2 == 0) : ?> </tr><tr><?php endif; ?>
<?php $i++; ?>

}

?> 
</table>


ist jetzt nicht besonders schön aufgeschrieben.. hab grad im Moment nicht soviel Zeit ;) , Prinzip erkennt man aber ist auch das selbe wie von Micha .. nur das man $i bei 1 beginnen sollte da im 2. Durchlauf dann $i = 2 -> also $i % 2 = 0 ist und vor dem nächsten durchlauf ein </tr><tr> eingefügt wird

Gruß Dannny

geschrieben von rich am 28.01.2010 - 15:21
ja super das hat Funkioniert =)
musste noch bisschen was ändern...
klasse ^^ danke

PHP-Quelltext
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 

<table width="500" border="0" cellspacing="0" cellpadding="1">


<?php
$sql
="SELECT gamelogo, spiele_id, spielname, genre FROM ".$prefix."spiele WHERE kategorie IN ('Action') order by spielname";
$result=mysql_query($sql);
?>
<tr>
<?php
$i 
1;
while(
$rows=mysql_fetch_array($result)){
?>
<td><A class=flyout href="<? echo $rows[gamelogo]; ?>"><img class=tmbright src="<? echo $rows[gamelogo]; ?>" width="80" height="80" alt="" border="0"></a></td>
<td><td><a href="game.php?id=<? echo $rows['spiele_id']; ?>"><font size="1"><? echo $rows['spielname']; ?></a></font> <td>&nbsp;&nbsp;</td>
<td><font size="1"><? echo $rows['genre']; ?></font> <td>&nbsp;&nbsp;</td> </td>

<?php if($i%== 0) : ?> </tr><tr><?php endif; ?>
<?php $i
++;

}
?>
</table>



Powered by: JBB v.2.0.4 Copyright ©2000-2006, www.javarea.de.