Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.