Gossamer Forum
Home : Products : DBMan : Customization :

rate a record in database

(Page 1 of 2)
> >
Quote Reply
rate a record in database
Hi,

I want to make an option in my database that lets users rate a certain record in the database. For that I created three fields: number of rates, total of rates and average rate. Now I wrote a php3 script that i call from the view results in this php script i call the modify record form. I want to modify the rate total by adding the rate of the user to it. My idea was to create a variable rate and to make something in db.cgi to add that rate to the total and 1 to the number of rates and calculate a new average for that record, but I don't know how to do that. Also when i call the modify_form_record sub from the php script i get an error unable to modify record/can't find requested record. All the fields are filled in by the php script though and when I press submit it will do it while nothing has changed. Can anybody help me a step further?
Thanks in advance, SeP

Quote Reply
Re: rate a record in database In reply to
I don't know anything about php, so I can't help you there.

I'm not sure how your rating system is set up. I'll need more details.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
that was a very quick reply! Thanks!

the php script outputs a page like this:

<html><head><title>Waardering voor dit werkstuk</title></head><body background="/achtergrond.gif">
<TR><TD width="375" valign="top"><FONT FACE="Arial,Helvetica" size="2"><H2>Geef je waardering voor dit werkstuk</H2>
<form method="get" action="http://www.huiswerkbegeleiding.nl/cgi-bin/dbman/db.cgi" name="stem">
<input type="hidden" name="db" value="werkstukken">
<input type="hidden" name="uid" value="default">
<input type="hidden" name="ID" value="4">
<input type="hidden" name="Vak" value="Wiskunde">
<input type="hidden" name="Titel" value="Wiskundige elementen in de grote piramide van cheops">
<input type="hidden" name="Trefwoorden" value="pi, pythagoras, elementen, piramide">
<input type="hidden" name="Omschrijving" value="Omschrijving"><input type="hidden" name="Cijfer" value="9,5">
<input type="hidden" name="File" value="wiskunde1">
<input type="hidden" name="Waardering_aant" value="0">
<input type="hidden" name="Waardering_tot" value="10">
<input type="hidden" name="Waardering_gem" value="0">
<select name = "Waardering">
<option value="5">Erg goed
<option value="4">Goed
<option value="3">Voldoende
<option value="2">Matig
<option value="1">Slecht
</select>
<input type="hidden" name="modify_form_record" value="1">
<input type="submit" value="Stem"></form>
</TD></TR></TABLE></body>
</html>

It takes the values for the hidden fields from the database record which should be rated by the user.

The select field waardering (rate in dutch) should be taken by the db.cgi script and added to a field named waardering_tot and the number of rates (waardering_aant) should be increased by 1. But I have also the problem that with this html file i get the error can't find requested record. (described in my previous post)

Since you're so great with perl, I am sure you can help me!

Kind regards, SeP

ps. the exact error i get is:

Error: Unable to Modify Record

There were problems modifying the record: unable to find record/no record specified:
Please fix any errors and submit the record again.

then (after changing nothing) when i press submit it works

Quote Reply
Re: rate a record in database In reply to
In Reply To:
Since you're so great with perl, I am sure you can help me!
That's sorta like saying, "Since you're great with English, I'm sure you can translate Swahili." Smile I have never encountered php and I don't have the slightest idea what it does.

Is is possible for you to work just with the DBMan files while we work out your other problem? It won't do any good to work on the rating mod unless you can actually access the database.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
But I gave you the output (in HTML) of the script, I am sure you understand that? The form in that HTML (forget about me ever saying php (-: calls the database named werkstukken. But than I get the described error. I have full access to the database, I am webmaster of the site, so it is possible for me to work with the dbman files ofcourse.

Kind regards, SeP

Quote Reply
Re: rate a record in database In reply to
If it can't find the requested record, then the key value of the record is not being found in the key field. Are you sure you have the correct name of the key field?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
This is the exact error I get:

Error: Unable to Modify Record

There were problems modifying the record: unable to find record/no record specified:
Please fix any errors and submit the record again.

I am sure I have the key value for the record, (ID)
this is the request to the database from the html file:
http://www.huiswerkbegeleiding.nl/cgi-bin/dbman/db.cgi?db=werkstukken&uid=default&ID=4...

what i see is a filled record form.
then (after changing nothing) when i press submit in the record form it works

as you see, the ID has a value there. The default user in the .cfg file has modification as possiblity so that's not the problem



Quote Reply
Re: rate a record in database In reply to
Now I see the problem. You have

<form method="get" action="http://www.huiswerkbegeleiding.nl/cgi-bin...

when it should be

<form method="post" action="http://www.huiswerkbegeleiding.nl/cgi-bin...

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
Hi, i changed the get into post but i still get the following error:

Error: Unable to Modify Record

There were problems modifying the record: unable to find record/no record specified:
Please fix any errors and submit the record again.

when i press the submit button, after having changed nothing the record is modified.

Quote Reply
Re: rate a record in database In reply to
You also have

<input type="hidden" name="modify_form_record" value="1">

That should probably be

<input type="hidden" name="modify_record" value="1">

Although I'm not sure why you don't just use

<input type="submit" name="modify_record" value="Stem">

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
YES !

now it seems to be working, the next problem is to take an input (not a db field input) and add that input to the db field waardering_tot (total of rates) and increase the number of waardering_aant (number of rates) and calculate a new average (waardering_gem) by dividing waardering_tot by waardering_aant. Do you know how to do this in perl?

Quote Reply
Re: rate a record in database In reply to
(I hope you don't mind. I edited your previous post so the page wouldn't scroll into the next county. Smile It was hard to read the other posts.)

Is this rating for an individual record? If so, how will you know which record is being rated?

How is the rating to be input?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
I don't mind you doing anything, you're so great helping me.
(-:
This rating is for an individual record and the record which is being rated is modified. Now i got it working so far that the (sorry) php script gets all the field values from dbman and outputs an html page that modifies the record by sending it all the same values (so actually it is not modified at all) and an extra value named waardering, which is not a field in dbman. The goal for this is to take that extra field and calculate a new total for the dbman field waardering_tot by adding the value of waardering to it. If that is done the dbman field waardering_aant has to be increased by 1 (number of rates) and than you can calculate a new average of rates (waardering_gem = dbman field) by deviding waardering_tot by waardering_aant

Quote Reply
Re: rate a record in database In reply to
Okay. I see.

In sub modify_record, after

Code:

if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}
add

Code:

if ($in{waardering}) {
$in{waardering_aant} = $data[the field number of waardering_aant] + 1;
$in{waardering_tot} = $data[the field number of waardering_tot] + $in{waardering};
}
As long as your rating is going to be at least equal to 1, this will work great. In other words, it won't work if one of the rating options is 0.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
I added the following code to sub modify_record on the place you indicated:

if ($in{waardering}) {
$in{waardering_aant} = $data[8] + 1;
$in{waardering_tot} = $data[7] + $in{waardering};
$in{waardering_gem}=$data[7]/$data[8];
}

but it doesn't work, i checked and the field waardering is really there. I don't know how to solve this, do you have great ideas for me?


Quote Reply
Re: rate a record in database In reply to
Did any of the field values change?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
no, none of them changed

Quote Reply
Re: rate a record in database In reply to
Are you sure that you put the code just before

$output .= &join_encode(%in);

Are you sure that your field names are exactly the same as in your .cfg file?

Are you sure that your field numbers are correct?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
all three I am sure about

Quote Reply
Re: rate a record in database In reply to
I don't know what to say, then. That would be the place to put the code. The %in hash is what is written to the database, so that's what should be changed.

Wait a minute. In your form you have

Code:

<input type="hidden" name="Waardering_aant" value="0">
<input type="hidden" name="Waardering_tot" value="10">
<input type="hidden" name="Waardering_gem" value="0">
<select name = "Waardering">
So the field names in

Code:

if ($in{waardering}) {
$in{waardering_aant} = $data[8] + 1;
$in{waardering_tot} = $data[7] + $in{waardering};
$in{waardering_gem}=$data[7]/$data[8];
}
are not the same. The field names must be *exactly* the same.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
IT WORKS !!!!!!!

You just made me a very happy man!

THANK YOU VERY MUCH FOR YOUR HELP!

I am going to polish it a bit, the average rating is now a number that can have as many digits after the comma as fits in the screen. I'm going to make it like if >4 then print **** if 5 print ******

If I have finished it i will send you the url so that you can see it in action. Thanks again and till next time!

Quote Reply
Re: rate a record in database In reply to
Please, Sep or JPDeni could you please make a mod of this , I dont know where to start it and I am also looking for this kind of mod include the image of each rating...please see the sample i saw at http://www.meetteens.com.

Quote Reply
Re: rate a record in database In reply to
The site you're referring to uses something from Links to deal with the rating. It's not the same as this one.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: rate a record in database In reply to
Hi Act,

I can't write you a mod for this, but if you read all the posts, I am sure you can do the same. If you'd like I'll post the php script I wrote but i don't know if that's of any use to you. You need to have a php enabled server.

Quote Reply
Re: rate a record in database In reply to
Hi Sep , my server has php too,but i think it would be easy to another here if be include rating from link2 in to dbman.
dEAR,JPDeni
Yes, it iclude the rating from link2 in to DBMan ,Could you add this mod please? ;-)

> >