General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 25th, 2002, 01:49 PM
mikle mikle is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 2 mikle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
devarticles.com rating system

hi
Could any1 plz write an article on how to implement a rating system such the one used in devarticiles?!


thanx

Reply With Quote
  #2  
Old September 25th, 2002, 02:13 PM
markerdave markerdave is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Illinois, USA
Posts: 71 markerdave User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I believe one has already been done. Take a look at Annette's article and see if it is what you are looking for.
__________________
Oh I wish, I wish I hadn't killed that fish...

Reply With Quote
  #3  
Old September 25th, 2002, 03:15 PM
mikle mikle is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 2 mikle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx markerdave

I though it would be a good idea to do it in php! The mentioned article is writen for ASP developeres!

Reply With Quote
  #4  
Old September 25th, 2002, 03:38 PM
markerdave markerdave is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Illinois, USA
Posts: 71 markerdave User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
mikle,

Do you know much ASP? I doubt that it would be too difficult to change the code from ASP to PHP.

Reply With Quote
  #5  
Old September 25th, 2002, 04:43 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
read the article, and if you need any help converting the asp to php, just post it here.

Reply With Quote
  #6  
Old September 26th, 2002, 09:28 AM
bigbear bigbear is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 13 bigbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi there

I am an absolute newbie to PHP, and as such, would not know how to convert the code from ASP to PHP. Would it be possible to have the rating script in PHP?

Thanks in advance.

Reply With Quote
  #7  
Old September 26th, 2002, 04:37 PM
1 man 1 man is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 9 1 man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up


Reply With Quote
  #8  
Old September 26th, 2002, 08:00 PM
bigbear bigbear is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 13 bigbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
1man
I've tried it, but after I click on the button the page stays on rate.php, with nothing showing up. No messages, nothing to say if the value has been entered to the db or otherwise.

btw: the name of my first file is article.php, and following the instructions, second file is rate.php. Am I doing things right?

Reply With Quote
  #9  
Old September 27th, 2002, 07:19 AM
1 man 1 man is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 9 1 man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
bigbear
I don't now where is the problem

the code dose not work with me!
i think the problem with id

you will see the URL like this :
http://you.com/rate.php?id=

i will try to check the problem
and answer you


1man

Reply With Quote
  #10  
Old September 27th, 2002, 07:25 AM
bigbear bigbear is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 13 bigbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes!!! That's the exact thing that I see when I click the button. The page is empty, and the URL is the way you described it.

Being a newbie to something as powerful and useful as PHP sucks... hopefully the book which I ordered will reach me soon.

Reply With Quote
  #11  
Old September 27th, 2002, 09:39 AM
1 man 1 man is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 9 1 man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb bigbear

OK .. try this scripts..

file name : article.php
PHP Code:
<?
$dbhost 
"localhost";
$dbname "book";
$dbpass "";
$dbuser "";




$DBC = @mysql_connect("$dbhost""$dbuser""$dbpass");
    if (!
$DBC) {
    echo 
"ERROR";
    exit();
    }

# select DB

$DBS = @mysql_select_db("$dbname");
    if (!
$DBS) {
    echo 
"ERROR";
    exit();
    } 
?>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#EFEFEF" width="100%" id="AutoNumber1" bgcolor="#EFEFEF">
  <tr>
    <td width="100%">
    <?
    $result2 
mysql_query("select * from rates");
while ( 
$row mysql_fetch_array($result2))
{
$id $row["id"];
?>
    <form method="GET" action=rate.php?id= <? echo $id?>>
      <p align="center"><?}?>
      <span class="blackSmall"><font size="1" face="Tahoma">id =
      <input type="text" name="ID" size="2" value="1"><br>
<b>How would you
      rate this article:&nbsp;&nbsp;&nbsp;Bad &nbsp;<input type="radio" value="2" name="rValue" checked>
      &nbsp;<input type="radio" value="4" name="rValue"> &nbsp;<input type="radio" value="6" name="rValue">
      &nbsp;<input type="radio" value="8" name="rValue"> &nbsp;<input type="radio" value="10" name="rValue">
      Good&nbsp;&nbsp;&nbsp;&nbsp; </b></font></span></p>
      <p align="center">
      <input type="submit" value="Rate" name="B1" style="color: #000080; border: 1px groove #000080; background-color: #FFFFCC"></p>
    </form>
    </td>
  </tr>
</table>

</body>

file name : rate.php
PHP Code:
<?
$dbhost 
"localhost";
$dbname "book";
$dbpass "";
$dbuser "";




$DBC = @mysql_connect("$dbhost""$dbuser""$dbpass");
    if (!
$DBC) {
    echo 
"ERROR";
    exit();
    }

# SELECT DB

$DBS = @mysql_select_db("$dbname");
    if (!
$DBS) {
    echo 
"ERROR";
    exit();
    }


$sql mysql_query("SELECT * from rates where id=$ID");
while (
$row=mysql_fetch_array($sql))
{
$id=$row["id"];
$FileName=$row["FileName"];
$Num_Votes=$row["Num_Votes"];
$Votes  =$row["Votes"];
$Rating=$row["Rating"];

$new_Votes=$Num_Votes+1;
$Votes2=$Votes+$rValue;
$Rating=round(($Votes/$new_Votes),2);

$sql2 mysql_query("UPDATE rates SET Num_Votes=$new_Votes, Votes=$Votes2, Rating=$Rating where id=$ID");

if (
$sql2) {
echo  
"Thank you. The article has rating = $Rating after your vote.";
}

}

?>

don't forget create the SQL table :
PHP Code:
 CREATE TABLE rates  (
ID int(5) DEFAULT  '0'  NOT NULL auto_increment,
FileName varchar(50)  NOT NULL,
Num_Votes int(4)  NOT NULL,
Votes int(5)  NOT NULL,
Rating int(5)  NOT NULL,
PRIMARY KEY  (ID)
); 

is every think ok ?

I hope that

1 MaN

Reply With Quote
  #12  
Old September 27th, 2002, 10:30 AM
bigbear bigbear is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 13 bigbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
1man... it doesn't work. After clicking on Rate button, it just stays at the page. Nothing seem to happen.

btw: How do I use images to display the ratings, and how do I use this on every article page?

Reply With Quote
  #13  
Old September 27th, 2002, 12:04 PM
1 man 1 man is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 9 1 man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0

man .. it's work with me !!

did you change any think?

look >> action=rate.php

1- How do I use images to display the ratings ?
use IF and round
like this :
$Rating2 = round($Rating);
if ($Rating = 5)) {
<img src="stars" alt="" border=0><img src="stars" alt="" border=0><img src="stars" alt="" border=0><img src="stars" alt="" border=0><img src="stars" alt="" border=0>
}
do like that with 4 & 3 & 2 & 1
i think .. But maybe that wrong

2- how do I use this on every article page?
go to table Article
and Add :
Votes & Num_Votes & Rate
ID will be article ID
that's all




1 MaN

Reply With Quote
  #14  
Old September 27th, 2002, 12:19 PM
bigbear bigbear is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 13 bigbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The only thing I changed was the name of the db.

Reply With Quote
  #15  
Old September 27th, 2002, 12:25 PM
1 man 1 man is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 9 1 man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0


i don't now where is the problem

check files name

and press on Rate 999 time

Reply With Quote
  #16  
Old September 27th, 2002, 12:41 PM
bigbear bigbear is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 13 bigbear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by 1 man


i don't now where is the problem

check files name