Jump to content

Need help making PHP count 3 sums to one and showing results.


murhapuro

Recommended Posts

Greetings

 

I have this rating script that shows ratings in stars. When visitors want to rate a dinner they have 3 choices:

 

Food quality: *****

Service: *****

Price: *****

 

Now this rating system works like a dream, but what i would like to do is, ask PHP to count all those three and

as result, show overall rating.

 

Overal: **********

 

In 10 stars, now the script has 10 stars as option and i would use it in this case. I know some basic php, but

very little. I'm trying to learn all the time, but this is beyond my skills. I added the script as detached, so

people can see how it works.

 

I use this to call the script, it also gets the id from database i created:

 

Food quality: *****

 

<?php

$query = "SELECT stars_ss FROM info WHERE (id ='$id');";

$result = mysql_query($query, $connection) or die("Error: " . mysql_error());

 

while ($row = mysql_fetch_array($result)) {

  echo rating_bar($row['stars_ss'],'5');

}

?>

 

 

Service: *****

 

<?php

$query = "SELECT stars_sq FROM info WHERE (id ='$id');";

$result = mysql_query($query, $connection) or die("Error: " . mysql_error());

 

while ($row = mysql_fetch_array($result)) {

  echo rating_bar($row['stars_sq'],'5');

}

?>

 

 

Price: *****

 

<?php

$query = "SELECT stars_ps FROM info WHERE (id ='$id');";

$result = mysql_query($query, $connection) or die("Error: " . mysql_error());

 

while ($row = mysql_fetch_array($result)) {

  echo rating_bar($row['stars_ps'],'5');

}

?>

 

Now comes the last one, i know how to make it 10 stars. It is the number ´5´ that

only needs to be changed '10', also i know how to make it unvotable, but how do i display it:

 

Overal: **********

 

<?php

 

 

<- but what comes in here??? ->

 

?>

 

 

If anyone could help with this, i would be so very happy. I need this because, i have search option and i would like

to call that overal in search. This would be so awesom to have, i just don't have the skills to do it yet. I would also

display it at the top of each page.

 

Thank you!

 

Murhapuro

 

[attachment deleted by admin]

Link to comment
Share on other sites

Here is all code that i use on the page that i display it in, not sure if i need to modify the source code of the rating script.

 

<?php

 

$t_host = 'localhost';

$t_user = 'sjhdsa';

$t_pass = 'ads2321';

$db = 'foodinfo';

$mytable = 'info';

$id = 'laxon_dinner';

$food = $row['laxon_dinner_so'];

$service = $row['laxon_dinner_ef'];

$price = $row['laxon_dinner_rs'];

$overall = $food+$service+$price;

 

$connection = mysql_connect($t_host,$t_user,$t_pass);

if (!$connection) {

die("database connection failed: " . mysql_error());

}

 

mysql_select_db($db,$connection);

if (!@db_select) {

die("Database selection failed: " . mysql_error());

}

?>

<?php require('_drawrating.php'); ?>

 

 

 

 

 

 

 

OVERALL RATING

  <?php

  $query = "SELECT id FROM ratings WHERE (id ='$overall');";

  $result = mysql_query($query, $connection) or die("Error: " . mysql_error());

 

  while ($row = mysql_fetch_array($result)) {

 

  echo rating_bar($row['$overall'],'10','static');

 

  }

  ?>

 

 

It just don't work. No errors

Link to comment
Share on other sites

this

OVERALL RATING
  <?php
  $query = "SELECT id FROM ratings WHERE (id ='$overall');";
  $result = mysql_query($query, $connection) or die("Error: " . mysql_error());

  while ($row = mysql_fetch_array($result)) {
  
   echo rating_bar($row['$overall'],'10','static');

  }

 

should be something like

 

OVERALL RATING

  <?php

  $query = "SELECT id FROM ratings;

  $result = mysql_query($query, $connection) or die("Error: " . mysql_error());

 

  while ($row = mysql_fetch_array($result)) {

 

$food = $row['stars_ss'];

$service = $row['stars_sq'];

$price = $row['stars_ps'];

 

  }

$overall = $food+$service+$price;

echo $overall;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.