If in WHILE-Schelife

S739H4N

Grünschnabel
Hallo!

Ich habe folgendes Problem:

Ich habe eine Datenbank mit den Werten URL, Beschreibung, Typ, Groesse, Extern

Ich habe folgende While-Schleife:
PHP:
while($downloadrow=mysql_fetch_assoc($downloadlist))

echo '<tr>
		<td style="width:50%"><a href="'.$downloadrow['URL'].'">'.$downloadrow['Beschreibung'].'</a></td>
		<td class="zelletippfullplattformwing" style="width:30%">'.$downloadrow['Typ'].'</td>
		<td class="zelletippfullplattformwing" style="width:20%">'.$downloadrow['Groesse'].'</td>
	</tr>';
Soweit funktioniert alles einwandfrei. (ja, ich hab im html ein <table> und </table> ;) )

Zusätzlich hat die DB ja noch den Wert Extern. Jetzt möchte ich, je nachdem ob der Wert Extern 1 oder 0 ist, dem Link einen unterschiedlichen Style zuordnen.

Sachen wie:
PHP:
while($downloadrow=mysql_fetch_assoc($downloadlist))

if($downloadrow['Extern']=="1"){$externclass=' class="type2" target="_blank"';}else{$externclass='';}

echo '<tr>
		<td style="width:50%"><a href="'.$downloadrow['URL'].'"'.$externclass.'>'.$downloadrow['Beschreibung'].'</a></td>
		<td class="zelletippfullplattformwing" style="width:30%">'.$downloadrow['Typ'].'</td>
		<td class="zelletippfullplattformwing" style="width:20%">'.$downloadrow['Groesse'].'</td>
	</tr>';
... funktionieren leider nicht.

Hat jemand einen Vorschlag? :)
 
Hi,

ich glaube dein Fehler ist, die 1 in Anführungsstriche zu setzen.
Du kannst also schreiben:
PHP:
if($downloadrow['Extern']==1)
oder noch besser
PHP:
if($downloadrow['Extern'])

Hier mein Test-Code:
PHP:
$downloadrow = array('Extern'=>1, 'URL'=>'http://www.google.de', 'Beschreibung'=>'Ich bin eine Beschreibung', 'Typ'=>'Ich bin ein Typ', 'Groesse'=>'100');

	if($downloadrow['Extern'])	// 1 NICHT in Anfuehrungsstrichen
		$externclass = ' class="type2" target="_blank"';
	else
		$externclass = '';

	echo 
		'<tr> 
        	<td style="width: 50%;">
				<a href="' . $downloadrow['URL'] . '"' . $externclass . '>' . $downloadrow['Beschreibung'] . '</a>
			</td> 
        	<td class="zelletippfullplattformwing" style="width: 30%;">' . $downloadrow['Typ'] . '</td> 
        	<td class="zelletippfullplattformwing" style="width: 20%;">' . $downloadrow['Groesse'] . '</td> 
    	</tr>';
 
Mach doch mal ein paar geschweifte Klammern. So wie es jetzt ist, wird nur ein einziges mal der echo gemacht, die while-Schleife aktualisiert immer nur die Variable $externclass. Versuch es mal so:

PHP:
while($downloadrow=mysql_fetch_assoc($downloadlist))
{
  if($downloadrow['Extern']=="1"){$externclass=' class="type2" target="_blank"';}else{$externclass='';}

  echo '<tr>
        <td style="width:50%"><a href="'.$downloadrow['URL'].'"'.$externclass.'>'.$downloadrow['Beschreibung'].'</a></td>
        <td class="zelletippfullplattformwing" style="width:30%">'.$downloadrow['Typ'].'</td>
        <td class="zelletippfullplattformwing" style="width:20%">'.$downloadrow['Groesse'].'</td>
    </tr>';  
}
 
Zurück