I have a small MySQL database for an online booking calendar. Now I wanted to get some stats out of this calendar. I am adding to each entry in the calendar values (full paid, partly paid and a status (paid, unpaid, reserved, etc)).
I have attached an image of the screenshot. As you can see, there are 4 different custom_attribute_ids. ID 1 is saving the status, ID 2 the full price and ID 3 the price already paid. The column entity_id is saving it together. So e.g. all 4 entries with entity_id 232 belongs together.
I now what to display the following:
1. The Sum of all full prices (so custom_attribute_id 2). This I have done with this code:
$result = mysql_query('SELECT SUM(attribute_value) AS value_sum
FROM custom_attribute_values WHERE custom_attribute_id=2');
$row = mysql_fetch_assoc($result);
$sum = $row['value_sum'];
This is working and showing me the sum of all full prices entered in the calender.
With the same code I am also showing the sum of the already partly paid amounts.
But now the problem, I want to show the sum of the attribute_value depending on the status. So the code should summarize all values when the custom_attribute_id=2 AND the attribute_value of the relevant entity_id is "Reserviert".
Would be very nice, if somebody could help me, or at least let me know, if this is possible. I am not able to re-design the database, as this code is given from the calendar system.
Here the db as text:
ID custom_attribute_value_id attribute_value entity_id attribute_category
1124 1 Anfrage 233 1
1125 2 1188 233 1
1126 4 233 1
1127 3 015757817858 233 1
1053 1 Reserviert 232 1
1054 2 1700 232 1
1057 3 017697544266 232 1
1058 4 232 1
1039 2 573 231 1
1040 3 088259216300 231 1
1042 1 Reserviert 231 1
1037 3 0043676845617203 230 1
1045 2 2346,50 230 1
1046 1 Reserviert 230 1
1032 1 Anfrage 229 1
1033 2 474 229 1
1034 3 229 1
1027 1 Anfrage 228 1
1029 3 228 1
1030 2 588,50 228 1
1024 3 01729843043 227 1
1025 1 Reserviert 227 1
1023 2 990 227 1