mijn vraag is hoe krijg ik dit script in een loop
en waarom krijg ik steeds de error:

Parse error: parse error in c:\phpdev\www\gallery\func\show_all_image.php on line 132

<?


$sql = "localhost";
$user = "root";
$pwd = "";
$dbn = "gallery";
mysql_connect($sql,$user,$pwd);
mysql_select_db($dbn);

$result1 = mysql_query('SELECT * FROM images WHERE id = 1');
if($result1 == 0)
{
echo 'no data returned';
}
else
{
$row1 = mysql_fetch_assoc($result1);

echo '<a href="func/get_image.php?id=1"><img width="50" height="50" src="' . $row1['link'] . '"></a>';

$result2 = mysql_query('SELECT * FROM images WHERE id = 2');
if($result2 == 0)
{
echo 'no data returned';
}
else
{
$row2 = mysql_fetch_assoc($result2);

echo '<a href="func/get_image.php?id=2"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result3 = mysql_query('SELECT * FROM images WHERE id = 3');
if($result3 == 0)
{
echo 'no data returned';
}
else
{
$row3 = mysql_fetch_assoc($result3);

echo '<a href="func/get_image.php?id=3"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result4 = mysql_query('SELECT * FROM images WHERE id = 4');
if($result4 == 0)
{
echo 'no data returned';
}
else
{
$row4 = mysql_fetch_assoc($result4);

echo '<a href="func/get_image.php?id=4"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result5 = mysql_query('SELECT * FROM images WHERE id = 5');
if($result5 == 0)
{
echo 'no data returned';
}
else
{
$row5 = mysql_fetch_assoc($result5);

echo '<a href="func/get_image.php?id=5"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result6 = mysql_query('SELECT * FROM images WHERE id = 6');
if($result6 == 0)
{
echo 'no data returned';
}
else
{
$row6 = mysql_fetch_assoc($result6);

echo '<a href="func/get_image.php?id=6"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result7 = mysql_query('SELECT * FROM images WHERE id = 7');
if($result7 == 0)
{
echo 'no data returned';
}
else
{
$row7 = mysql_fetch_assoc($result7);

echo '<a href="func/get_image.php?id=7"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result8 = mysql_query('SELECT * FROM images WHERE id = 8');
if($result8 == 0)
{
echo 'no data returned';
}
else
{
$row8 = mysql_fetch_assoc($result8);

echo '<a href="func/get_image.php?id=8"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result9 = mysql_query('SELECT * FROM images WHERE id = 9');
if($result9 == 0)
{
echo 'no data returned';
}
else
{
$row9 = mysql_fetch_assoc($result9);

echo '<a href="func/get_image.php?id=9"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result10 = mysql_query('SELECT * FROM images WHERE id = 10');
if($result10 == 0)
{
echo 'no data returned';
}
else
{
$row10 = mysql_fetch_assoc($result10);

echo '<a href="func/get_image.php?id=10"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result11 = mysql_query('SELECT * FROM images WHERE id = 11');
if($result11 == 0)
{
echo 'no data returned';
}
else
{
$row11 = mysql_fetch_assoc($result11);

echo '<a href="func/get_image.php?id=11"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
$result12 = mysql_query('SELECT * FROM images WHERE id = 12');
if($result12 == 0)
{
echo 'no data returned';
}
else
{
$row12 = mysql_fetch_assoc($result12);

echo '<a href="func/get_image.php?id=12"><img width="50" height="50" src="' . $row1['link'] . '"></a>';
?>
De error: je sluit de else niet af.

De loop:


<?php
    for ($i = 1; $i < 13; $i++)
{
	$result{$i} = mysql_query('SELECT * FROM images WHERE id = '.$i);
	if($result{$i} == 0)
	{
		echo 'no data returned';
	}
	else
	{
		$row{$i} = mysql_fetch_assoc($result{$i});
		echo  '<a href="func/get_image.php?id='.$i.'"><img    width="50" height="50" src="' . $row{$i}['link'] . '"></a>';
	}
}
?>
<?php
$sql = "localhost";
$user = "root";
$pwd = "";
$dbn = "gallery";
mysql_connect($sql,$user,$pwd);
mysql_select_db($dbn);

$result = mysql_query("SELECT * FROM images LIMIT 0,13")
while($row = mysql_fetch_assoc($result)){
echo '<a href="func/get_image.php?id='. $row['id'] .'$row"><img width="50" height="50" src="'.$row['link'].'"></a>';
}
?>

Wel moet je database tabel een id bevatten..

Reageren