I have a div of 40 images(nopreview.png), What I am trying to do is to replace the nopreview.png with the images from db, so if I have 10 images in DB, so out of 40 nopreview.png will be replaced with images from DB keeping the 30 nopreview.png as it is.
HTML
<div class="holder">
<img src="nopreview.png"/>
<img src="nopreview.png"/>
</div>
PHP
$uid="XXXXX";
$check = "SELECT rqid FROM users WHERE fbid = $uid LIMIT 0,250";
$rs = mysqli_query($con,$check);
if(mysqli_num_rows($rs)>0):
while($row = mysqli_fetch_assoc($rs)):
$reqid= $row['rqid'];
$requests = explode(',',$reqid);
foreach(array_unique($requests) as $request_id) {
echo $request_id."<br>";
echo"<img src='https://graph.facebook.com/$request_id/picture?width=78&height=78' />";
echo "<hr>";
}
endwhile;
endif;
Stuck in where to put the images div?
You're trying to work with PHP like Javascript.
Sccrap your HTML file. Your file "images.php" will look sth like:
<div class="holder">
<?php
$uid="XXXXX";
$check = "SELECT rqid FROM users WHERE fbid = $uid LIMIT 0,250";
$rs = mysqli_query($con,$check);
$imagecount=0;
while($row = mysqli_fetch_assoc($rs)) {
$reqid= $row['rqid'];
$requests = explode(',',$reqid);
foreach(array_unique($requests) as $request_id) {
echo"<img src='https://graph.facebook.com/$request_id/picture?width=78&height=78' />";
$imagecount++;
}
}
for(;$imagecount<40;$imagecount++) {
echo("<img src=\"nopreview.png\" />");
}
?>
</div>
So you will always have your 40 images, starting with the available ones and filling at the end with nopreview.png if required.