简体   繁体   English

获取DISTINCT行的函数

[英]Function to get a DISTINCT row

There are lots of articles on getting distinct rows through a sql statement but I havent found the help I need after a SQL statement has already run. 关于通过sql语句获取不同行的文章很多,但是在运行SQL语句后,我还没有找到需要的帮助。 Im very new to PHP and I am using the DHTMLX library to render a grid. 我对PHP非常陌生,我正在使用DHTMLX库渲染网格。 The unusual syntax used to render the grid is throwing me off big time. 用于渲染网格的异常语法使我大失所望。 What I want is simply distinct rows in my grid only. 我想要的只是网格中唯一的不同行。 Everything works great, I just need help getting a function together that will return distinct rows. 一切都很好,我只需要帮助将一个函数放在一起就可以返回不同的行。 In my code below I managed to get the two functions that are commented out to work great so I have been using them as a roadmap but I just can't pull the "distinct function" together due to a lack of familiarity with loops. 在下面的代码中,我设法使两个函数都被注释掉,可以很好地工作,因此我一直将它们用作路线图,但是由于对循环的缺乏了解,我无法将“独特的函数”组合在一起。 Can someone help me with the syntax needed to have this function return distinct rows. 有人可以帮我提供此函数返回不同行所需的语法。 I think array_unique will come into play but Im pretty lost at this point. 我认为array_unique会起作用,但是我在这一点上很迷失。

<?php
require("codebase/grid_connector.php");
$res = mysql_connect("localhost", "1newuser", "");
mysql_select_db("supplydb");



function distinct($result)
{
    $grab = array_unique($rows->get_value("group"));

}



/*function formatting($row){
$data = $row->get_value("gpo_item");
if ($data == 1)
$row->set_value("gpo_item",Yes);
else
$row->set_value("gpo_item",No);
}    */
/*function calck($action){
$data1 = $action->get_value("list_price");
$data2 = $action->get_value("sugg_price");
$sum = (($action->get_value("sugg_price") / $action->get_value("list_price")) - 1) * 100 ;
$sum2 = round($sum);
$sum3 = abs($sum2);        
$action->set_value("discount",$sum3);
}    */
$gridConn = new GridConnector($res, "MySQL");
//$gridConn->event->attach("beforeRender","formatting");
//$gridConn->event->attach("beforeRender","calck");
$gridConn->event->attach("beforeRender", "distinct");
$gridConn->render_sql("SELECT * FROM manufacturers JOIN submissions on manufacturers.manufacturer_id=submissions.manufacturer_id JOIN products on products.product_id=submissions.product_id JOIN product_group on submissions.category=product_group.id", "submission_id", "date,man_name,group,requesting_clinician, requesting_clinician_email, contract_number");
?> 

All array_unique does is eradicates duplicate values within a given array. array_unique所做的全部工作是根除给定数组中的重复值。

Why can you not just specify a distinct lookup within your sql? 为什么不能仅在sql中指定不同的查找?

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

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