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 7 years ago.
Improve this question
I'm thinking adding a number to a row, and in an array (or something) i can declare what it is.
Like this:
mySQL table
id type duration
1 2 5
2 3 4
3 6 10
PHP array or something
type 2 = jumping
type 3 = biking
type 6 = painting
This way it will be easier to add, or remove a "type".
But sorry, i have no idea how to do this.
The effect I'm looking for is to display
Johan was jumping for 5 minuts
Johan was biking for 4 minuts
Johan was painting for 10 minuts
Help much appreciated!
I would suggest to safe everything to a DB instead of hard-coding it in your code. So taking your table as basis:
Table: t1
id type duration
1 2 5
2 3 4
3 6 10
Table: t2
type_id whatever
2 jumping
3 biking
6 painting
You could use a SQL-Join to combine those two tables:
SELECT t1.id, t2.whatever, t1.duration
FROM t1
JOIN t2
ON t1.type = t2.type_id
will produce
1 jumping 5
2 biking 4
....
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 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 debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to make a relation between two tables. I can do what I want with fetching the data with PHP and using returning value again in a query. But as far as I researched, it doesn't seem an efficient method.
How can I get the winning coupons when I'm finalizing the bet #3 as YES with a SQL query?
(It should return 3 and 4)
Coupon table,
ID coupon_id bets bets_played played_by
0 2 2 yes JOHN
1 2 3 no JOHN
2 3 1 yes JANE
3 3 3 yes JANE
4 4 3 yes SARAH
5 4 2 no SARAH
Bets table,
ID result
1 yes
2 no
3 NULL
Thank you.
select distinct c.*
from coupon c
join bets b on b.result = c.bets_played and b.result = 'yes'
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 7 years ago.
Improve this question
I have a databade table as follows
id A
1 2
2 4
3 5
4 9
I want the result to show as below by doing repeated addition
A B
2 2
4 6
5 11
9 20
At this point, we're supposed to ask you what you've tried, but anyway...
SELECT x.a
, SUM(y.a) b
FROM my_table x
JOIN my_table y
ON y.id <= x.id
GROUP
BY x.id;
http://sqlfiddle.com/#!9/d66f6/1
SELECT a,
IF(#b IS NULL, #b:=a, #b:=#b+a) as B
FROM table1
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 . "'";
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