while schleife?

GrObY

Mitglied
ich habe hier ein news script das in einer while schleife leuft und einmal eine durchnummerrierung jeweils vor jeder news bis zu 5 das heiss das vor jeder news <a name="5"></a> mit abfallender zahl steht soweit so gut:P
nur habe ich jetzt das problem das jede news dopelt kommt weil sie beide while schleifen durchgeht wie kann ich das ändern?
PHP:
mysql_select_db("$db_db");

$abfrage = mysql_query("select name, email, topic, img, text, unix_timestamp(time) from news order by time desc limit 10");

while (list($name, $email, $topic, $img, $text, $zeit) = mysql_fetch_row ($abfrage))

 {
$datum = date ("d.m.Y" , $zeit);	
$uhrzeit = date ("H:i", $zeit);		
								
								

$news = "";	        			  	
														
	
$news = nl2br($text);
			
?>
<?php $x=5; while(0 < $x) { echo("<a name='".$x."'></a>\n"); $x--; ?>
<table cellpadding="5" cellspacing="0" class="news" width="600" border="0" align="left">
<tr><td background="img/newso.jpg" height="32" width="600" leftmargin="0" topmargin="0" cellpadding="0" cellspacing="0"></td></tr> 
<tr><td width="600" leftmargin="0" topmargin="0" cellpadding="0" cellspacing="0"><img src="img/<? echo $img ?>"><font size="12px"></br><b><? echo "$topic"; ?></font></b></br></br><font size="12px"> <? echo "$news"; ?></font></td></tr>
<tr><td background="img/newsu.jpg" height="28" width="600" leftmargin="0" topmargin="0" cellpadding="0" cellspacing="0"><font size="2"> <? echo "$datum $uhrzeit"; ?> von<font size="2" color="#336699"> <? echo "  |  <a href='mailto:$email'>$name</A>"; ?> </font> </td></tr>
</table></br>
<?
 }   

?>
<?
 }   

?>
 
also ich weiss ned genau, was du willst, aber das sollte gehn:
PHP:
<?php
mysql_select_db("$db_db");

$abfrage = mysql_query("select name, email, topic, img, text, unix_timestamp(time) from news order by time desc limit 10");

$num = mysql_num_rows($abfrage);

while (list($name, $email, $topic, $img, $text, $zeit) = mysql_fetch_row ($abfrage))

 {
$datum = date ("d.m.Y" , $zeit);    
$uhrzeit = date ("H:i", $zeit);        
                                
                                

$news = "";                              
                                                        
    
$news = nl2br($text);
            
echo("<a name='".$num."'></a>\n"); $num--;
?>
<table cellpadding="5" cellspacing="0" class="news" width="600" border="0" align="left">
<tr><td background="img/newso.jpg" height="32" width="600" leftmargin="0" topmargin="0" cellpadding="0" cellspacing="0"></td></tr> 
<tr><td width="600" leftmargin="0" topmargin="0" cellpadding="0" cellspacing="0"><img src="img/<? echo $img ?>"><font size="12px"></br><b><? echo "$topic"; ?></font></b></br></br><font size="12px"> <? echo "$news"; ?></font></td></tr>
<tr><td background="img/newsu.jpg" height="28" width="600" leftmargin="0" topmargin="0" cellpadding="0" cellspacing="0"><font size="2"> <? echo "$datum $uhrzeit"; ?> von<font size="2" color="#336699"> <? echo "  |  <a href='mailto:$email'>$name</A>"; ?> </font> </td></tr>
</table></br>
<?php
 }   

?>
 
Hab nicht ganz verstanden was du willst!
Du willst, dass vor jedem News einmal der A-Tag mit entsprechender Zahl steht?

Dann lass einfach die 2. While-Schleife weg, mach das mit dem $x direkt in die 1.While Schleife und Schreibe vor jede News das echo.


[edit]Verdammt, viel zu spät :rolleyes:
 
Zurück