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]

well the over all start should be out of 15, three categories all with 5 stars.

 

Then for the over you could do

 

$food = $row['stars_ss']

$service = $row['stars_sq'],

$price = $row['stars_ps'],

 

$overall = $food+$service+$prive

 

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

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;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.