简体   繁体   English

在同一mysql列中显示两个单独的值时出现问题

[英]Problems displaying two seperate values from the same mysql column

I have a mysql table called custom_values where in the table exists two columns, One called "custome_field_id" and one called "value". 我有一个名为custom_values的mysql表,该表中存在两列,一列称为“ custome_field_id”,另一列称为“ 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 “ custom_field_id”列显示的“ date_value”值的custom_field_id为33,“ order”值的值为237

What I would like to do is structure my php query so that in one select statement, I can display both of these values. 我想做的是构造我的php查询,以便在一个select语句中,我可以显示这两个值。

for example end up with an $actual_date and $Order variable that I can use. 例如,最后我可以使用$ actual_date和$ Order变量。

Here is my current select statement that at this moment retrieves the "order" value. 这是我当前的select语句,此刻现在检索“ order”值。 But I need to show both... I tried using Alias in in my select statement but it didnt work for me... 但是我需要同时显示两个...我在我的select语句中尝试使用Alias,但对我没有用...

$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. 我强烈建议您在Ruby中将其构建为Redmine插件。 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. 但是,使用Redmine中的CustomField和CustomValue类将为您完成所有抽象。

You could even use the Redmine API [1] to access the data using HTTP. 您甚至可以使用Redmine API [1]通过HTTP访问数据。

[1] http://www.redmine.org/projects/redmine/wiki/Rest_api [1] http://www.redmine.org/projects/redmine/wiki/Rest_api

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; 如果满足以下条件: 在同一个数据库中,您有2列,第一列包含2个不同的数字,如果第二列有两个不同的值; therefore you have 2 rows per item to pull out 因此每个项目有2行可拉出

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 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM