简体   繁体   English

PHP - 从同一行的不同列中获取和比较行值

[英]PHP - Get and compare row value from a different column for the same row

I'm attempting to edit a custom function and struggling to get the row value for a particular custom column ('rank_td') to compare against its other columns (rank_lw and rank_lm), all inside a HTML table.我正在尝试编辑自定义函数并努力获取特定自定义列 ('rank_td') 的行值,以便与其他列(rank_lw 和 rank_lm)进行比较,所有这些都在 HTML 表中。

Tried a fair few variations and can't get it going.尝试了相当多的变化,但无法继续。

Any ideas?有任何想法吗?

function custom_value($cellValue, $dataColumnHeader, $rank_td_value) {

if($dataColumnHeader == "rank_lw" || $dataColumnHeader == 'rank_lm'){

    $row['rank_td']->$cellValue = $rank_td_value;

    if($rank_td_value == $cellValue){
                $styleColor = 'color:blue;';
             }else if($rank_td_value < $cellValue){ 
                $styleColor = 'color:green;';
             }else{
                $styleColor = 'color:red;';
             } 
        return $class_name.'<span style="'.$styleColor.'">'.$cellValue.'</span>';
}

return $cellValue; }

样本数据

You are not calling the global variable $row which exists outside the scope of this function - hence my comment that it doesn't look like it belongs here.您没有调用存在于该函数范围之外的全局变量$row - 因此我的评论是它看起来不属于这里。 If you want to be able to access a variable from outside a function you need to either pass that variable in, or declare it using the global keyword.如果您希望能够从函数外部访问变量,您需要传入该变量,或者使用 global 关键字声明它。 Here is a very basic example of this:这是一个非常基本的例子:

$row['some_value'] = "value1";

function scopeTest($var1) {
    $row['some_value'] = $var1;//local variable $row created
}
function scopeTestTwo($var1) {
    global $row;//variable outside the function
    $row['some_value'] = $var1;
}

scopeTest("jam");
print_r($row);//Array ( [some_value] => value1 )
scopeTestTwo("jam");
print_r($row);//Array ( [some_value] => jam )

in your code you also have this在你的代码中你也有这个

return $class_name.'<span....

but $classname is not defined so either it is redundant and you should remove it (because this will cause a php notice and anyway redundant code is, well, redundant) or it should be defined somewhere which means something has been missed out但是$classname没有定义所以要么它是多余的,你应该删除它(因为这会导致一个 php 通知,无论如何冗余代码是,好吧,多余的)或者它应该被定义在某处,这意味着某些东西被遗漏了

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

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