So I have this existing snippet on custom php.. I am trying to check whether there are existing painting details in the db.. if painting details r found i need to get details of the latest added ones upto count 6 & print detail accordingly. Here is my code->
<?php
$pData=mysql_query("select * from painting_data");
if($pData === FALSE) {
echo "<div class='well'>No painting available.</div>";
}
else{
$pDet=mysql_query("Select * from painting_data order by padd desc limit 6");
while($pD=mysql_fetch_assoc($pDet)){
$pId=$pD['pid'];
$pTitle=$pD['ptitle'];
$pImg=$pD['pimg'];
?>
<div class="col-lg-2 col-md-4 col-sm-6 img-recent-container">
<img role="button" class="img-thumbnail img-responsive img-recent" onclick="location.href='?p=<?php echo $pId; ?>'" src="..<?php echo $pImg;?>" alt="<?php echo $pTitle;?>"/>
</div>
<?php }
} ?>
Now I am new to CI.. & i am confused on how to separate the data retrieval properly. Since the else block has a query in it as well.. I am confused how not to include it in the view.