Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, i'm trying to save myself from

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, i'm trying to save myself from creating too many tables in my mysql database so what i need todo is a page which handles the values sent from a form where a user rates a product and the rating they give is called $rate and the users name is called $username. What I need todo is a statement which adds $rate and $username into the same field and the rating is added onto the current rating (as if it's a total rating) and the username is placed at the end, for example.

#|#9#|#username1 username2 username3

Then I need tobe able to retrieve the total rating so the value can be displayed and i need tobe able to check if the username has already been inserted the next time the user rates the product.

I'd be greatful if someone could help me out or lead me in the right direction. Thanx
 
Hi pal :)

I do not quite understand why you want to do this so complicated...
Whats the problem with creating a table with two columns
"username" and "rating"?

CREATE TABLE `rating` (
`username` VARCHAR(255) NOT NULL,
`product` TINYINT NOT NULL,
`rating` TINYINT NOT NULL,
);

With this table you have the advantage of enabling the users to
a) rate for numerous products
b) see how many users have rated it
c) see how user 'x' rated in general
d) see how product 'x' is rated by others

cu, Sascha cu, Sascha
 
I suppose it wont hurt todo another table. I was trying todo something I read but it all got abit too complicated. Cheers mate
 
Well, database design is easy, and you should use as many tables as you need, not more, not less. You should think well about what you want to do. That way, you can solve easely your problems.

If you want a new feature in your program, you can see if you need to add a new table, if you need to add a new column to an existing table, or if you can fetch the data using the tables you already have in your model.

In this case, you should add the table. It's the best choise. Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hi, I added a table and added the script below, the original if statement detects if the user is logged in (which works fine) and then it determines whether the user has already voted. I thought I got this working but I seem to be able to vote for the same band more than once. Would you be able to help me out. Thanx

if($xmbuser) {
$result_id = $db->query("SELECT uid from xmb_nfp_members where username = '$xmbuser'");
$user_id = $db->result($result_id,"uid") ;
$query = $db->query("SELECT * FROM rateband_tbl WHERE band_id = '$id' & user_id = '$user_id'");
$results = $db->num_rows($query);

if ($results == '1') {
echo '<font face=&quot;Verdana&quot; size=&quot;2&quot;>You have already voted</font>';
exit;
}

$db->query(&quot;INSERT INTO rateband_tbl VALUES('$user_id','$id','$rate')&quot;);
{
echo '<font face=&quot;Verdana&quot; size=&quot;2&quot;>Thankyou for your vote. Click here to close this window</font>';
exit;
}
} else {
echo '<font face=&quot;Verdana&quot; size=&quot;2&quot;>You\'re not a registered member of the site</font>';
exit;
}
 
oh and $rate is the rating sent $xmbuser is the members username and i know that both these values are picked up correctly.
 
oh and $rate is the rating sent $xmbuser is the members username and i know that both these values are picked up correctly as the correct information is inserted into the database it just doesn't detect if the user has rated the band before and it adds another column
 
For your origonal question. That would only for for so many people. You need to think that you will have millions of people using the feature. The table design you gave will work for only a limited number of users. Plus you would be increasing runtime by parsing the user field out. If you have good DB design, don't worry about many tables. Mike Wills
AS400 Programmer
[pc2]

Please, if you find my post useful, let me know. [thumbsup2]
 
hmm not sure if that was supposed to help, I kinda understand it. Is there a fix for the solution I have used?
 
Try this one:

$query = $db->query(&quot;SELECT * FROM rateband_tbl WHERE band_id = $id & user_id = $user_id&quot;);

BTW, where is $id set? cu, Sascha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top