Translate

Thursday 18 September 2014

To display Star images in Database by using PHP

Explaination :
             When we enter the star rating that rate is to insert in database as a number like 1,2,3,...
             that star rating we want to dispaly not in a number we want to doasplay in an image means
             we can use the above coding it a simple way to dispalt star image using php.I hope this 
             tutorial is very usefull the Developers as well as beginners also.

Note : The star images u have to download in google and try this.   

$row['star_rate'];=>star_rate-Database Table field name



Coding In PHP:

<?php
$variable=mysql_query("select  * from tbl_name");
$i = 1;
while ($row = mysql_fetch_array($variable))
{
?>
<td align="left" class="normal">
<?php
if($row['star_rate']==0)
{
?>
<img src="images/star0.jpg" alt="Star Rating" height="16" id="thumb">

<?php } else if($row['star_rate']==1) {?>
<img src="images/star1.jpg" alt="Star Rating" height="16" id="thumb">

<?php } else if($row['star_rate']==2){ ?>
<img src="images/star2.jpg" alt="Star Rating" height="16" id="thumb">

<?php } else if($row['star_rate']==3){ ?>
<img src="images/star3.jpg" alt="Star Rating" height="16" id="thumb">

<?php } else if($row['star_rate']==4){ ?>
<img src="images/star4.jpg" alt="Star Rating" height="16" id="thumb">

<?php } else if($row['star_rate']==5){ ?>
<img src="images/star5.jpg" alt="Star Rating" height="16" id="thumb">

<?php } ?>
</td>

No comments:

Post a Comment