Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have grades from 1 to 5 where 1 is the best and 5 is the worst(But not just integral numbers like 1, also 1.14 and so on).
I want to calculate how many stars each grade would be(5 stars would be the best, 1 star the worst - 3 would stay 3 of course - but the rest?)
I googled to get the result but I'm not finding anything helpful. Maybe I'm missing the forest for the trees, I don't know. Basically it would be the reverse number I guess?
I want to do that in PHP.
Pretty straightforward I would think:
$new_grade = 6 - $old_grade;
Or for a more generic solution:
$new_grade = $grade_max + $grade_min - $old_grade;
Star = 6 - Grade
So:
5 → 1
4 → 2
3 → 3
2 → 4
1 → 5
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What type of series it is and how to generate this by php program?
0 1 3 2 6 7 5 4 12 13 15 14 ...
Observation: The successive difference of the entity is 1
Example:
Difference of 0 and 1 is 1
Difference of 3 and 2 is 1
Difference of 6 and 7 is 1
Difference of 5 and 4 is 1
Difference of 12 and 13 is 1
Difference of 15 and 14 is 1
Please help ...
Its a Decimal Equivalent of Gray code up to n. I have written a code to generate the Gray code for any Number, Use this to generate a series. I have used Javascript, but you can choose any language you want.
Number.toGrayCode = function(n) {
if (n < 0) {
throw new RangeError("cannot convert negative numbers to gray code");
}
return n ^ (n >>> 1);
};
for( var i=0;i<=10;i++)
console.log(Number.toGrayCode(i));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a table named 'prices' and every range has its price.
course_id start end price
-----------------------------
1 1 5 20
1 5 10 18
1 10 100 15
-------------------------
I have for example $course_id = 1 and $weeks_num = 8.
How can I get the price of that course?
In the given example I should have 18 because 8 exists between 5 and 10.
You can use BETWEEN clause. http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between
...
WHERE 8 BETWEEN start AND end
...
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm building a browser game which you can shoot missiles on factories.
This is example of a similar SQL table:
user_ID iron steel metal gold
1 21 30 39 25
2 7 10 25 50
I need each missile to destroy 1 factory.
For example I shoot 10 missile, so 10 factories are destroyed. But I need it to have completely randomly and even.
The problem is if according to this SQL table, if I shoot for example 40 missile on user_ID '2'.
In best case I destroy 10 factories of each kind. But how can I do it when I don't know if there is enough of each kind?
First, divide the number of missiles by the number of factory types that have at least 1 factory. If all the types have at least this many factories, subtract this from each column.
If any of the types have less than this, they'll be totally wiped out. Reduce them to 0 and subtract their original totals from the number of missiles. Then start again, using just the remaining missiles.
Repeat this until you use up all the missiles or all factories are wiped out.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a voting table called product_reviews, with a field that is ENUM from 1 to 5 called rating.
I want to get average rating from all rows with product_id 1665. I am using a star rating system so the average cannot be with decimals. Must be a number from 1 to 5.
Thank you very much.
SELECT round(avg(rating)) as average_review,
count(rating) as number_of_reviews
FROM product_reviews
WHERE product_id = 1665
You need to use round here since avg will return a value between 1.0 and 5.0, and if you use floor or ceil you're effectively eliminating 1 or 5 from the possible results unless all reviews on the product have that score.
Also, you'll alienate your users if they can openly see a product got 50 reviews with 1 star, and 1 review with 2 stars, and you're showing an average score of 2 stars next to that. It'll make your site seem unreliable which is usually not a good thing for a site that contains reviews. For this reason most star rating systems are also capable of showing partial stars to make it more precise.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a variable $z_name=carredwidetastymodern...; (here I show just a part of string "opelmazdabmwhynday..." (in fact, it's a very long string)
I would like fill in ref field from $z_name, could anybody help me?
id name ref id name ref
10 opel 10 opel car
11 apple 11 apple red
12 river 12 river wide
13 food 13 food tasty
14 pc 14 pc modern
(here I show just a part of table. It's a very big table, a lot of records)
Use loop by all records and add inside
mysql_query("UPDATE table_name SET ref = '$z_name' WHERE id =$id");
Well, maybe I'm missing something... I would say that
"REPLACE INTO table_name SET ref = '" . $z_name . "'";