PHP、Dwoo - 变量

发布于 2024-08-16 21:19:16 字数 1286 浏览 6 评论 0原文

我正在尝试将其转换为 dwoo:

foreach($duplicates as $duplicate)
{
    echo "<tr>";
    foreach($column_list as $column)
    {
        if(@$duplicate{$column . "_diff"} == 1)
        {
            $id_is_different = '';
            echo "<td style=\"background: #333333\" >". $duplicate{$column} ."</td>\n";
        }
        else
        {
            echo "<td>" . $duplicate{$column} ."</td>\n";
        }
    }
    echo "</tr>";
}

我有这个:

{foreach $duplicates duplicate}
<tr>
    {foreach $column_list column}
    <td{if $duplicate.$column.'_diff' == 1} style="background: #333"{/if}>{$duplicate.$column}</td>
    {/foreach}
</tr>            
{/foreach}

除了第四行的 .$column.'_diff' 之外,它工作得很好。知道如何使用 dwoo 将后缀添加到变量吗?!?!

谢谢!

编辑

我可能应该解释得更好。

基本上,我正在做的是从 mysql 表 $column_list 中获取列名列表(使用“SHOW COLUMNS FROM...”)。然后执行另一个查询来选择数据,在该查询中,我将每列中的数据与另一个表匹配,并添加一个前缀为“_diff”的列,因此如果我有一个名为“name”的列,我也有一列“name_diff”(这些列不在 $column_list 中),其值为 1 或 0。1 或 0 仅表示天气或不与其他表中匹配的数据。无论如何,列数和列名总是在变化,所以我不能真正在代码中使用任何列名。所以....

对于 dwoo,{$duplicate.$column} 会类似于 $duplicate['name'];我想做的是动态添加后缀“_diff”,这样我就可以更改单元格的背景颜色......我知道这非常令人困惑!我真的不擅长解释事情!

I'm trying to convert this to dwoo:

foreach($duplicates as $duplicate)
{
    echo "<tr>";
    foreach($column_list as $column)
    {
        if(@$duplicate{$column . "_diff"} == 1)
        {
            $id_is_different = '';
            echo "<td style=\"background: #333333\" >". $duplicate{$column} ."</td>\n";
        }
        else
        {
            echo "<td>" . $duplicate{$column} ."</td>\n";
        }
    }
    echo "</tr>";
}

I have this:

{foreach $duplicates duplicate}
<tr>
    {foreach $column_list column}
    <td{if $duplicate.$column.'_diff' == 1} style="background: #333"{/if}>{$duplicate.$column}</td>
    {/foreach}
</tr>            
{/foreach}

With the exception of: .$column.'_diff' on the 4th line, it works perfectly. any idea how i can add the suffix to the variable with dwoo?!?!

Thanks!

EDIT

I probably should have explained better.

Basically, what I'm doing is grabbing a list of column names from a mysql table, $column_list(using "SHOW COLUMNS FROM..."). Then doing another query to select the data, in that query, i'm matching data in each column to another table and adding a column with a prefix of "_diff" so if i have a column named "name" i also have a column "name_diff"(these columns are not in $column_list) that has a value of either 1 or 0. the 1 or 0 just signify weather or not the data matched in the other table. anyhow, The number of columns and column names are always changing so I can't really use any column names in the code. so....

with dwoo, {$duplicate.$column} would be something like $duplicate['name']; and what i'm trying to do is dynamically add the suffix "_diff" so i can change the background color of the cell... I know that was super confusing! I'm really bad at explaining things!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稍尽春風 2024-08-23 21:19:16

恐怕目前唯一的解决方案是执行以下操作:

{foreach $duplicates duplicate}
<tr>
    {foreach $column_list column}
        {$diffcol = cat($column '_diff')}
        <td{if $duplicate.$diffcol == 1} style="background: #333"{/if}>{$duplicate.$column}</td>
    {/foreach}
</tr>            
{/foreach}

I'm afraid the only solution for now is to do the following :

{foreach $duplicates duplicate}
<tr>
    {foreach $column_list column}
        {$diffcol = cat($column '_diff')}
        <td{if $duplicate.$diffcol == 1} style="background: #333"{/if}>{$duplicate.$column}</td>
    {/foreach}
</tr>            
{/foreach}
祁梦 2024-08-23 21:19:16

试试这个

{foreach $column_list column}
    <td{if $duplicate.$column.last == 1} style="background: #333"{/if}>{$duplicate.$column}</td>
    {/foreach}

try this

{foreach $column_list column}
    <td{if $duplicate.$column.last == 1} style="background: #333"{/if}>{$duplicate.$column}</td>
    {/foreach}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文