while: bei mysql_fetch_array fehlt erster Datensatz (MYSQL)
Jakob Schneider
- php
Moin Leute,
folgender Code hier sollte mir die Threads meines Boards ausgeben
(Ich hab die Datenbank neuinstalliert, jetzt geht LIMIT auch wieder :-))
if($threaddata=mysql_fetch_array($doselectthreads))
{
print '<div class="divthreads">
<table class="tablethreads">
<tr><td class="tdthreadsdesc">Icon</td><td class="tdthreadsdesc">Thema</td><td class="tdthreadsdesc">Autor / Datum</td><td class="tdthreadsdesc">Antworten</td><td class="tdthreadsdesc">Klicks</td><td class="tdthreadsdesc">Letzte Antwort</td></tr>';
}
else
{
print '<div class="divthreads"><p> Es gibt keine Threads, die den Sortierungskriterien entsprechen</p></div>';
}
while($threaddata=mysql_fetch_array($doselectthreads))
{
if($threaddata['icon'])
{
print '<tr><td class="tdthreads" style="width:25px"> <img src="'.$threaddata['icon'].'" alt="Icon"></td>';
}
else
{
print'<tr><td class="tdthreads" style="width:25px"> </td>';
}
print '<td class="tdthreads" style="width:450px;"> <a href="showthread.php?threadid='.$threaddata['id'].'">'.$threaddata['titel'].'</a> </td>';
print '<td class="tdthreads" style="width:200px"> '.$threaddata['datum'].' von ';
$threaddata['name']=getusername($threaddata['name']);
if(user_registered($threaddata['name']))
{
print'<a href="showprofile.php?member='.$threaddata['name'].'">'.$threaddata['name'].'</a></td>';
}
else
{
print $threaddata['name'].'</td>';
}
if(!$threaddata['clicks'])
{
$$threaddata['clicks']=0;
}
print '<td class="tdthreads" style="width:51px"> '.getthreadreplies($threaddata['id']).' </td>';
print '<td class="tdthreads" style="width:30px"> '.$threaddata['clicks'].' </td>';
$lastreplydata=getlastreplyofthread($threaddata['id']);
if(!$lastreplydata['datum']&&!$lastreplydata['name'])
{
$lastreplydata['datum']='';
$lastreplydata['name']='-';
}
print '<td class="tdthreads" style="width:175px;"> '.$lastreplydata['datum'];
if($lastreplydata['name']!='-')
{
print ' von ';
}
if(user_registered($lastreplydata['name']))
{
print'<a href="showprofile.php?member='.$lastreplydata['name'].'">'.$lastreplydata['name'].'</a></td>';
}
else
{
print $lastreplydata['name'].'</td>';
}
print'</table></div>';
}
}
Es wird zuerst geprüft, ob Threads vorhanden sind [if($threaddata=mysql_fetch_array($doselectthreads))], dann werden sie mit [while($threaddata=mysql_fetch_array($doselectthreads))] ausgegeben.
Solange ich nur einen Datensatz in der DB habe, wird mit while() nichts ausgegeben, jedoch wird der eine Datensatz von [if($threaddata=mysql_fetch_array($doselectthreads))] erkannt. Nur die while-Schleife gibt ihn komischerweise nicht aus.
Wenn ich mehr Datensätze habe werden alle, außer dem ersten, korrekt ausgegeben.
Hat jemand einen Lösungsansatz
Danke schonmal!
LG Jakob
Hi!
if($threaddata=mysql_fetch_array($doselectthreads))
An dieser Stelle wird der ewrste Datensatz geholt
[...]
while($threaddata=mysql_fetch_array($doselectthreads))
hier der 2. bis zum letzten.
Grüße
Andreas
Hi,
dankeschön, weiß ich Bescheid :-)
LG Jakob