PHP 将列数据添加到表 IF 条件为真

问题描述

这是一个艰难的过程。我不确定如何解释这一点,但我会尽力而为。我有一个表,其中所有值都来自基于搜索表单的数据库

table

如果某个条件为真,最后一列“地图链接”出现:

$path = 'C:/my/path/here/maps/';

$find_ein = array_column($data,'ein');
                    
foreach($find_ein as $map_ein){
    $map = $path.$map_ein.'_integration_map.xlsx';
    if(file_exists($map)){
        echo '<th class="report-headings">Map Link</th>';
        $map_link = $map;
    }else{
        //echo "no";
    }
}

我正在尝试将 $map_link 回显到此列中。在此示例中,$map_link 仅属于第 2 行,因为并非所有 EIN 都有地图链接。对于那些这样做的人,EIN # 包含在文件名中,这就是我检查 if(file_exists) 的原因。 $map_link 反而被添加到每一列:(您几乎看不到,但在表格顶部,我回显 $map_link显示我返回的内容,因此应该只有 1 个值进入 Map Link柱子):

table2

foreach ($data as $entry){
    // create a new row in the table
    echo '<tr style="text-align:center;line-height:32px;">';

    $count = count($entry);
    $y = 0;
    while ($y < $count){
        $current_row = current($entry);
        // then fill the columns
        echo '<td>'.$current_row.'</td><td><button><a href="'.$map_link.'">Map Link</a></button></td>';
                                
        next($entry);
        $y = $y + 1;
    }
    echo '</tr>';
}

我不知道这些是否有意义,但这是我在那里发现的最聪明的社区,所以我希望有人能够提供帮助!而且我非常非常新。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)