Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/22204-displaying-data-from-my-sql/
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?
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]

Archived

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

×
×
  • Create New...

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.