Reputation: 5629
is somthing like that possible?
for ($i = 1; $i <= 15; $i++) {
$var = "bild" . $i;
if (!empty ($row->bild.$i)) {
echo '
<div class="item">
<img border="no" class="bildschatten" src="include/images/projekte/'.$row->bild . $i.'" />
</div>
';
}
}
how should it look correctly? problem is:
I fetch objects from a mysql database, in this table each object has 15 images
bild1 .. bild15
Now I want to iterate over this 15 images and want to check if the colum is empty or not.
the problem I have is here:
$row->bild.$i
that contains not the value of column bild1.. bild15 ... it only contains the value of $i
thanks
Upvotes: 1
Views: 49
Reputation: 133380
You could fetch the result as an array uning
$row = db_fetch_array($result)
and then accessing
$var = "bild" . $i;
if (!empty ($row[$var])) {
Upvotes: 1
Reputation: 9583
This is called variable of variables, You need to access something like this $row->$var
.
Complete Solution:
for ($i = 1; $i <= 15; $i++) {
$var = "bild" . $i;
if (!empty ($row->$var)) {
echo '
<div class="item">
<img border="no" class="bildschatten" src="include/images/projekte/'.$row->$var.'" />
</div>
';
}
}
For more details checkout the Manual.
Upvotes: 1