Jump to content

Archived

This topic is now archived and is closed to further replies.

edkuan

displaying data from my sql

Recommended Posts

Hi guys

im new to php so i hope u guys could help me
i've created a table in my sql listing the diners name and rating given :

diner name        rating (star)
Diner A              4
Diner B              6
Diner C              2
Diner D              3

what I want to do is displaying it like this in the page
diner name                rating (star)
Diner A                    ****
Diner B                    ******
Diner C                    **
Diner D                    ***

the astrix here could be a gif of a star , how do I do this so that php would dynamicly create the star

im using php , dmx
thanks

Share this post


Link to post
Share on other sites
Well you could use the switch function,

www.php.net/switch

Its easy ....

like

"Mysql info here pulling the rating and storing in $rating"
switch ($rating) {
case 1:
  echo "This is a * dinner";
  break;
case 2:
  echo "This is a ** dinner";
  break;
case 3:
  echo "This is a *** dinner";
  break;
}
And so on... You get it?

Share this post


Link to post
Share on other sites
Thats a bit of a long winded way of doing it. You can use the [url=http://uk.php.net/manual/en/function.str-repeat.php]str_repeat[/url] function.

Example:
[code=php:0]$rating = str_repeat("*", $row['dinner_rating']);
echo $rating;[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.