Jump to content


Photo

displaying data from my sql


  • Please log in to reply
2 replies to this topic

#1 edkuan

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
thanks


#2 AbydosGater

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

Posted 27 September 2006 - 03:54 PM

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?
www.abydosgaters.com

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

#3 wildteen88

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.

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users