SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 7th, 2002, 08:06 AM
Thissel Thissel is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 Thissel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP and MySQL problem

Hey folks.
I have a problem with a "5 star rating system" based on this tutorial. First of all I have created a database called netstronauts and a table with the same name. In this table I have created three columns named tut_num_votes, tut_rating and tut_id. Then I created the rate.php and the tutorials.php.

The code for these pages are:

rate.php:
Code:
<html>
<head>
<title>Rate</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<? function ratemenu($tut_id){ 
    echo "<form name='rating' method='post' action='tutorials.php'> 
    <font class='subfont'>Rate this Tutorial:</font> 
    <select name='rating'> 
    <option value='5.0' selected>5 - Excellent!</option> 
    <option value='4.0'>4</option> 
    <option value='3.0'>3 - Fair</option> 
    <option value='2.0'>2</option> 
    <option value='1.0'>1 - Poor</option> 
    <option value='0.0'>0 - Awful!</option> 
    <input type='hidden' name='cmd' value='do_rating'> 
    <input type='hidden' name='tut_id' value='$tut_id'> 
    <input type='submit' value='Go!'> 
    </select> 
    </form>"; 
} 
?>  

<p><? ratemenu($tut_id) ?></p>
<p></p>
</body>
</html>


tutorials.php:
Code:
<? function do_rating($tut_id, $rating){    
	if (session_is_registered("rating$tut_id")){ 
        echo "Sorry! You have already voted!"; 
    } else { 
        
$database = mysql_connect("localhost","xxx","xxx");
mysql_select_db("netstronauts",$database);
$get_count = mysql_query("SELECT tut_rating, tut_num_votes FROM netstronauts WHERE tut_id='$tut_id'") or die(mysql_error());
while(list($tut_rating, $tut_num_votes)=mysql_fetch_array($get_count)){
		
            $new_count = ($tut_num_votes + 1); 
            $tut_rating2 = ($tut_rating * $tut_num_votes); 
            $new_rating = (($rating + $tut_rating2) / ($new_count)); 
            $new_rating2 = number_format($new_rating, 2, '.', ''); 
            $update_rating = mysql_query("UPDATE table SET tut_rating=$new_rating2,tut_num_votes=$new_count WHERE tut_id='$tut_id'"); 
            $sessionvar = "tut$tut_id"; 
            session_register($sessionvar); 
             
            echo "<div align="center"><b> 
            <p>Thanks for your vote!</p> 
            <p>The new rating for this tutorial is: 
             
            $new_rating2 out of 5</p>"; 
        } 

    } 
    echo "<p align="center"><a href="javascript:history.back();"><<       
    Back</a> | <a href="/index.php">Main Page</a> | <a href="/tutorials.php">Tutorial 
    Index>></a></p></b> 
    "; 
}
?>
<?

function tut_stars($tut_rating){ 
    if((($tut_rating >= 0)or($tut_rating == 0)) && ($tut_rating <= 0.50)){ 
        echo "<img src="/images/stars/0o5.gif" width="70" height="18">"; 
    } 
    if((($tut_rating >= 0.50)or($tut_rating == 0.50)) && ($tut_rating <= .99)){ 
        echo "<img src="/images/stars/05o5.gif" width="70" height="18">"; 
    } 
    if((($tut_rating >= 1.00)or($tut_rating == 1.50)) && ($tut_rating <= 1.49)){ 
        echo "<img src="/images/stars/1o5.gif" width="70" height="18">"; 
    } 
    if((($tut_rating >= 1.50)or($tut_rating == 1.50)) && ($tut_rating <= 1.99)){ 
        echo "<img src="/images/stars/15o5.gif" width="70" height="18">"; 
    } 
    if((($tut_rating >= 2.00)or($tut_rating == 2.00)) && ($tut_rating <= 2.49)){ 
        echo "<img src="/images/stars/2o5.gif" width="70" height="18">"; 
    } 

    if((($tut_rating >= 2.50)or($tut_rating == 2.50)) && ($tut_rating <= 2.99)){ 
        echo "<img src="/images/stars/25o5.gif" width="70" height="18">"; 
    } 

    if((($tut_rating >= 3.00)or($tut_rating == 3.00)) && ($tut_rating <= 3.49)){ 
        echo "<img src="/images/stars/3o5.gif" width="70" height="18">"; 
    } 

    if((($tut_rating >= 3.50)or($tut_rating == 3.50)) && ($tut_rating <= 3.99)){ 
        echo "<img src="/images/stars/35o5.gif" width="70" height="18">"; 
    } 
    if((($tut_rating >= 4.00)or($tut_rating == 4.00)) && ($tut_rating <= 4.49)){ 
        echo "<img src="/images/stars/4o5.gif" width="70" height="18">"; 
    } 
    if((($tut_rating >= 4.50)or($tut_rating == 4.50)) && ($tut_rating <= 4.99)){ 
        echo "<img src="/images/stars/45o5.gif" width="70" height="18">"; 
    } 
    if($tut_rating == 5.0){ 
        echo "<img src="/images/stars/5o5.gif" width="70" height="18">"; 
    } 
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<? do_rating('$tut_id', $rating) ?>
<? tut_stars($tut_rating) ?>
</body>
</html>


I have tried almost everything but it seems like the whole "calculating process" doesn't work. Do any of you have an idea how to fix this??

Best Regards

Mathias

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > PHP and MySQL problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway