I have two tables in my database. I use MySQL.
Basically, I created an app to manage 'Futsal's Field Order'
So, here we go :
The first table is named Lapangan means "Field in Indonesian" :
mysql> SELECT id,nama_lapangan FROM lapangan;
+----+---------------+
| id | nama_lapangan |
+----+---------------+
| 1 | Lap 01 |
| 2 | Lap 02 |
| 3 | Lap 03 |
+----+---------------+
3 rows in set (0.00 sec)
And The Second Table is Booking : ,
mysql> SELECT id, nomor_booking, date_booking, date_end_booking, lapangan_id FROM `yfutsal`.`booking` LIMIT 1000;
+----+---------------+---------------------+---------------------+-------------+
| id | nomor_booking | date_booking | date_end_booking | lapangan_id |
+----+---------------+---------------------+---------------------+-------------+
| 1 | 1 | 2017-07-16 10:00:00 | 2017-07-16 12:00:00 | 1 |
| 2 | 2 | 2017-07-16 15:00:00 | 2017-07-16 16:00:00 | 3 |
+----+---------------+---------------------+---------------------+-------------+
For example, The user start at 08.00 AND end in 23.00.
It means, lap 1 is not available on 10.00 - 12.00.
And same too that lap 3 is not available on 15.00 - 16.00.
The goal is, I want to display the Lapangan (field) that available with hour so, the cashier can choice it.
Something like this :
+----+---------------+----------------------+-----------------------+
| id | nama_lapangan | Available Start | Available End |
+----+---------------+----------------------+-----------------------+
| 1 | Lap 01 | 2017-07-16 08:00:00 | 2017-07-16 09:59:00 |
| 1 | Lap 01 | 2017-07-16 12:01:00 | 2017-07-16 23:00:00 |
| 2 | Lap 02 | 2017-07-16 08:00:00 | 2017-07-16 23:00:00 |
| 3 | Lap 03 | 2017-07-16 08:00:00 | 2017-07-16 14:59:00 |
| 3 | Lap 03 | 2017-07-16 16:01:00 | 2017-07-16 23:00:00 |
+----+---------------+----------------------+-----------------------+
Please advise.
just change
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
in config/config to
$root = "https://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$root";
base_url() function returns value based on base_url constant , you just have to make the constant return https instead of http
try this to set base_url in proper way:
$root=(isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) ? "https://" : "http://").$_SERVER['HTTP_HOST'];
$root.= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
Related
I'm not sure this is possible with just SQL...any help will be appreciated:
I'm trying to retrieve a value in a column in table B (tblProduct).
The column name is actually defined in reference table A (tblConfig_Group).
So, essentially, I'm given the tblConfig_Group.groupCode and tblProduct.VCI values
I need to retrieve the value in the appropriate column in tblProduct set in dbColumnUK.
tblConfig_Group:
+----+-----------+-------------+
| id | groupCode | dbColumnUK |
+----+-----------+-------------+
| 01 | A | WindowGBP_A |
| 02 | B | WindowGBP_B |
| 03 | C | WindowGBP_C |
| 04 | D | WindowGBP_D |
+----+-----------+-------------+
tblProduct:
+----+---------+-------------+-------------+-------------+-------------+
| id | VCI | WindowGBP_A | WindowGBP_B | WindowGBP_C | WindowGBP_D |
+----+---------+-------------+-------------+-------------+-------------+
| 01 | vci1 | 1 | 11 | 21 | 31 |
| 02 | vci2 | 2 | 12 | 22 | 32 |
| 03 | vci3 | 3 | 13 | 23 | 33 |
| 04 | vci4 | 4 | 14 | 24 | 34 |
+----+---------+-------------+-------------+-------------+-------------+
You can use a query like the following:
SELECT CASE g.dbColumnUK
WHEN 'WindowGBP_A' THEN p.WindowGBP_A
WHEN 'WindowGBP_B' THEN p.WindowGBP_B
WHEN 'WindowGBP_C' THEN p.WindowGBP_C
WHEN 'WindowGBP_D' THEN p.WindowGBP_D
END AS col
FROM tblProduct AS p
CROSS JOIN (SELECT dbColumnUK FROM tblConfig_Group WHERE groupCode='A') AS g
WHERE VCI = 'vci2'
Demo here
Working in Redmine, I need to copy(not move) data from certain rows to other rows based on matching project id numbers with time entries.
I have included a diagram of the table "custom_values" and my understanding of the design below(CURRENT DATA):
+----+-----------------+---------------+-----------------+-------+
| id | customized_type | customized_id | custom_field_id | value |
+----+-----------------+---------------+-----------------+-------+
| 1 | Project | 1 | 1 | 01 |
| 2 | TimeEntry | 1 | 4 | 01 |
| 3 | Project | 2 | 1 | 02 |
| 4 | TimeEntry | 2 | 4 | 02 |
| 5 | Project | 3 | 1 | 03 |
| 6 | TimeEntry | 3 | 4 | |
| 7 | Project | 4 | 1 | 04 |
| 8 | TimeEntry | 4 | 4 | |
+----+-----------------+---------------+-----------------+-------+
At the risk of oversimplifying,
"id" = The primary key for each entry in custom_values
"customized_type" = Specifies which db table the row is referring to.
"customized_id" = Specifies the primary key for the db table entry previously specified in "customized_type".
"custom_field_id" = Specifies which custom field the row is referring to. Redmine admins can arbitrarily add and remove custom fields.
"value" = The data contained within the custom field specified by
"custom_field_id"
In my situation, the values listed in "value" are representing unique customer id numbers. The customer id numbers did not always get entered with each time entry. I need to copy the customer numbers from the project rows to the matching time entry rows. Each time entry has a project_id field.
So far, here is my mangled SQL query:
SELECT
custom_field_id,
custom_values.value AS 'CUSTOMER_NUMBER',
custom_values.customized_id AS 'PROJECT_ID_NUMBER',
custom_values.customized_type,
time_entries.comments AS 'TIME_ENTRY_COMMENTS'
FROM
redmine_tweaking.custom_values
LEFT JOIN
redmine_tweaking.time_entries ON custom_values.customized_id = time_entries.project_id
WHERE
custom_values.customized_type='Project' AND custom_values.custom_field_id=1;
The query I have so far allows me to see that I have the time entries connected properly to their matching projects, but that is all I have been able to figure out. So in other words, this SQL statement does not exactly solve my problem.
Plus, even if it did work, I think the way I laid it out looks like 200 lbs of bird poop. There must be a better/more optimized way to do this.
Any help would be greatly appreciated. I am relatively new and I have been pouring hours into solving this problem.
UPDATE:
Ok, here is the time_entries table:
+----+------------+---------+----------+-------+----------+-------------+------------+-------+--------+-------+---------------------+---------------------+
| id | project_id | user_id | issue_id | hours | comments | activity_id | spent_on | tyear | tmonth | tweek | created_on | updated_on |
+----+------------+---------+----------+-------+----------+-------------+------------+-------+--------+-------+---------------------+---------------------+
| 1 | 1 | 1 | 1 | .25 | test | 9 | 2015-11-04 | 2015 | 11 | 45 | 2015-11-04 08:18:12 | 2015-11-04 10:18:12 |
| 2 | 2 | 1 | 1 | .25 | test2 | 9 | 2015-11-04 | 2015 | 11 | 45 | 2015-11-04 09:18:12 | 2015-11-04 12:18:12 |
+----+------------+---------+----------+-------+----------+-------------+------------+-------+--------+-------+---------------------+---------------------+
As opposed to the original table that I first posted, the expected output would show this:
+----+-----------------+---------------+-----------------+-------+
| id | customized_type | customized_id | custom_field_id | value |
+----+-----------------+---------------+-----------------+-------+
| 1 | Project | 1 | 1 | 01 |
| 2 | TimeEntry | 1 | 4 | 01 |
| 3 | Project | 2 | 1 | 02 |
| 4 | TimeEntry | 2 | 4 | 02 |
| 5 | Project | 3 | 1 | 03 |
| 6 | TimeEntry | 3 | 4 | 03 |
| 7 | Project | 4 | 1 | 04 |
| 8 | TimeEntry | 4 | 4 | 04 |
+----+-----------------+---------------+-----------------+-------+
I have a table named nca_totals.
Table: nca_totals
+----------+-----------+------------+--------------+
| total_id | nca_total | nca_date | account_type |
+----------+-----------+------------+--------------+
| 13 | 10450 | 2015-01-21 | DBP-TRUST |
| 14 | 5000 | 2015-02-05 | DBP-TRUST |
| 15 | 7000 | 2015-04-02 | DBP-TRUST |
| 16 | 4000 | 2015-05-02 | DBP-TRUST |
+----------+-----------+------------+--------------+
Now I want to display all the data by quarter base on its date. Let's say I want to display all the records who belong to 1st Quarter like this:
+----------+-----------+------------+--------------+
| total_id | nca_total | nca_date | account_type |
+----------+-----------+------------+--------------+
| 13 | 10450 | 2015-01-21 | DBP-TRUST |
| 14 | 5000 | 2015-02-05 | DBP-TRUST |
+----------+-----------+------------+--------------+
This date belongs to the 1st quarter of the year (Jan, Feb, March). I only have this query to select the date and return its quarter number as:
SELECT QUARTER('2015-01-11'); /* returns 1 */
How can I combine that query to display all the records by quarter ? Can anyone help ? Thanks.
select *
from nca_totals
where QUARTER(nca_date) = 1
SELECT
CEIL(MONTH(`nca_date`) / 3) AS `quarter`
FROM `nca_totals`;
I have a database full of about 500 records that work in the following way
id | group | date | team1 | team2
I want to add a new field "matchid", and fill it in with a number 1 - 8 per group. So the record set would look like
1 | 2 | 2014-03-09 15:00:00 | j1 | j2
2 | 2 | 2014-03-09 16:30:00 | j3 | j4
3 | 2 | 2014-03-10 15:00:00 | j5 | j6
4 | 2 | 2014-03-10 16:30:00 | j7 | j8
5 | 2 | 2014-03-11 15:00:00 | j9 | j10
6 | 2 | 2014-03-11 16:30:00 | j11 | j12
7 | 2 | 2014-03-12 15:00:00 | j13 | j14
8 | 2 | 2014-03-12 16:30:00 | j15 | j16
9 | 3 | 2014-03-13 15:00:00 | j1 | j2
10 | 3 | 2014-03-14 16:30:00 | j3 | j4
11 | 3 | 2014-03-15 15:00:00 | j5 | j6
12 | 3 | 2014-03-16 16:30:00 | j7 | j8
13 | 3 | 2014-03-17 15:00:00 | j9 | j10
14 | 3 | 2014-03-18 16:30:00 | j11 | j12
15 | 3 | 2014-03-19 15:00:00 | j13 | j14
16 | 3 | 2014-03-20 16:30:00 | j15 | j16
This then goes on and on, so this happens weekly, groups get together on sequential times, usually 2 groups per day, so think of this as like a round like in sporting events.
What I need to do is get the new ID which will be something like
01
02
..
and so on to 08.
What I need to do is look at the date for the group and rank everything in order then update the matchid field with the sequential number.
The reason this needs to be done is that the managers have added a new matchid which relates to the game per match per group.
I am looking for a way to programatically do this within SQL so that I dont have to manually update every record.
I ended up doing this programatically in PHP and mysql.
I itereated through each "group" and tested the date values to order them into an array. once i had them ordered my date in the array, I was able to easily add the numbers sequentially.
I am working on an online time card system and have ran into a road block. What I need to do is calculate in each row the timeIn and timeOut for a date the employee might clock in and out several times a day. I have a working query to find the total for the entire day but not for each individual row. I have included the structure of the database table with some examples of what I would like to see.
+----+------------+----------+---------+------------------------------+-------------+------------+-----------+----------+
| id | employeeID | date | timeIn | jobDescription | equipType | unitNumber | unitHours | timeOut |
+----+------------+----------+---------+------------------------------+-------------+------------+-----------+----------+
| 8 | 1 | 01/15/13 | 7:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 9:30 PM |
| 9 | 1 | 01/15/13 | 10:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 12:00 PM |
| 10 | 1 | 01/16/13 | 7:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 5:30 PM |
| 11 | 1 | 01/17/13 | 7:00 AM | Loaded sand in Jefferson | Excavator | 345 | NULL | 5:30 PM |
| 12 | 1 | 01/18/13 | 8:00 AM | Backfill in Whispering Creek | Skid Loader | 297 | NULL | 5:30 PM |
| 13 | 1 | 01/19/13 | 8:00 AM | Backfill in Whispering Creek | Skid Loader | 297 | NULL | 3:30 PM |
| 1 | 1 | 01/20/13 | 6:00 | | Excavator | 01E | 7238 | 17:00 |
| 2 | 1 | 01/21/13 | 6:00 | Worked in Jefferson | Excavator | 01E | 7238 | 17:00 |
| 3 | 1 | 01/22/13 | 6:00 | Worked in Jefferson | Excavator | 02E | 7238 | 17:30 |
| 4 | 1 | 01/23/13 | 6:00 | Worked in Whispering Creek | Skid Loader | 32SL | 2338 | 18:30 |
| 5 | 1 | 01/24/13 | 8:00 | Worked in Hubbard | Scraper | 54C | 9638 | 11:30 |
| 6 | 1 | 01/25/13 | 8:00 | Worked in Jefferson | Dozer | 4D | 941 | 19:30 |
| 7 | 1 | 01/26/13 | 8:00 | Pushed Snow | Loader | 950H | 342 | 20:30 |
+----+------------+----------+---------+------------------------------+-------------+------------+-----------+----------+
Ok so what I would like to see is that for example the date 01/15/13 appears twice with different timeIn and timeOut values I would like to get a value back saying that in row with the id 8 there was 2:30 hours, then get another value back saying that in the row where id is 9 there was 2:00 hours. I would like to accomplish this with one query if possible.
This is my query to get the time for the entire day:
SELECT `employeeID`, SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(`timeOut`, `timeIn`)))) AS `totalTime` FROM `timeRecords` WHERE `date` = "01/15/13" AND `employeeID` = 1 GROUP BY `employeeID`;
If I understand you correctly you need this?
SELECT `employeeID`, TIMEDIFF(`timeOut`, `timeIn`) AS `totalTime` FROM `timeRecords`;
You can use PDO query to query your database which returns result set as array of associative array. For better performance you can use PDO prepare/execute.
<?php
function getTimeByRow($connection) {
$sql = "SELECT `employeeID`, TIMEDIFF(`timeOut`, `timeIn`) AS `totalTime` FROM `timeRecords`";
foreach ($connection->query($sql) as $row) {
print $row['employeeID'] . "\t";
print $row['totalTime'] . "\n";
}
}
?>
So you want to do something like this:
select employeeID, date, TIMEDIFF(timeout, timein) from timeRecords where date = x and employeeID = y