Jump to content


displaying data from my sql

  • Please log in to reply
2 replies to this topic

#1 edkuan

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 27 September 2006 - 04:04 AM

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

#2 AbydosGater

  • Members
  • PipPipPip
  • Advanced Member
  • 435 posts
  • LocationAlways at computer!

Posted 27 September 2006 - 03:54 PM

Well you could use the switch function,


Its easy ....


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

Current Project: Blog Application.. Undecided name.. Status: Coming along great.

#3 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 September 2006 - 05:31 PM

Thats a bit of a long winded way of doing it. You can use the str_repeat function.

$rating = str_repeat("*", $row['dinner_rating']);
echo $rating;

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users