Forums

PHP

This topic is locked

displaying data from my sql

Posted 27 Sep 2006 06:01:36
1
has voted
27 Sep 2006 06:01:36 ede edd posted:
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

Replies

Replied 03 Oct 2006 19:34:11
03 Oct 2006 19:34:11 Tracy Sweder replied:
I am assuming that you are only going to be using a maximum rating of 6 stars? Being that it is possible for more than one diner to have the same rating - I would break it up into two separate tables like so:

Diners:
ID | Name | rating |

Ratings
rating | pic

Then, you set the ID as the primary key in Diners, and rating as a foreign key in diners
Make rating a primary key in Ratings
If you are using phpMyAdmin then you need to also click (from viewing the structure of the Diners table) on the little relationship table icon and let it know that rating in Diners is related to rating in Ratings.

Once you have done that you can setup a query in your page that looks something like this:

SELECT * FROM Diners, Ratings WHERE Ratings.rating = Diners.rating

Then when you place the commands in your page to put the info in you can choose to insert whatever is in the "Pic" field from the Ratings table for the appropriate rating of the Diner.

Reply to this topic