I have a mysql table called custom_values where in the table exists two columns, One called "custome_field_id" and one called "value".
The "value" column holds two different values that I need to pull and display on my page. One value is an "order number" value and the other is a "date" value. The "custom_field_id" column shows a custom_field_id of 33 for the "Date" value and 237 for the "order" value
What I would like to do is structure my php query so that in one select statement, I can display both of these values.
for example end up with an $actual_date and $Order variable that I can use.
Here is my current select statement that at this moment retrieves the "order" value. But I need to show both... I tried using Alias in in my select statement but it didnt work for me...
$stmt = $con->prepare("SELECT custom_values.value, issues.subject, issue_statuses.name,
issues.due_date, issues.id as issuesid,
users.firstname, users.lastname
FROM redmine.issues join redmine.projects on issues.project_id=projects.id
left join redmine.users on issues.assigned_to_id=users.id
left join redmine.custom_values ON issues.id=custom_values.customized_id
left join issue_statuses on issues.status_id=issue_statuses.id
where projects.id='".$_SESSION['id']."'
and custom_values.custom_field_id=237 ORDER BY $order ASC");
$stmt->execute();
Any help is appreciated!
I'd strongly advise to build this in Ruby as a Redmine plugin then. Dealing with the database at this level is error-prone; working with the CustomField and CustomValue classes in Redmine however, will do all the abstraction for you.
You could even use the Redmine API [1] to access the data using HTTP.
SELECT v_order.value my_order
, v_date.value date
, i.subject
, s.name
, i.due_date
, i.id issuesid
, u.firstname
, u.lastname
FROM issues i
JOIN projects p
ON p.id = i.project_id
LEFT
JOIN users u
ON u.id = i.assigned_to_id
LEFT
JOIN custom_values v_order
ON v_order.customized_id = i.id
AND v_order.custom_field_id = 237
LEFT
JOIN custom_values v_date
ON v_date.customized_id = i.id
AND v_date.custom_field_id = 33
LEFT
JOIN issue_statuses s
ON s.id = i.status_id
WHERE p.id = "_SESSION['id']"
ORDER
BY $order ASC
If the following is right: In the same database, you have 2 columns first contains 2 different numbers in case of two different values in the second column; therefore you have 2 rows per item to pull out
Please correct me if I missunderstood.
Try the following:
... AND ( custom_values.custom_field_id=value_1 OR custom_values.custom_field_id=value_2 ) ORDER ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.