如何在HTML内使用baseurl链接编写td标签?

时间:2020-11-03 14:23:19

标签: php html codeigniter html-table echo

              <tbody>
                  <!-- Table contents-->
                  <?php
                     $i=1;
                     foreach($data as $row)
                     {
                        echo "<tr>";
                        echo "<td style='display:none;'>".$row->partner_id."</td>";
                        echo '<td><img src="<?php echo base_url()?>assets/img/erplanka/profilepic.png" class="img-fluid img-thumbnail profimg"></td>';
                        echo "<td>".$row->cmp_name."</td>";
                        echo "<td>".$row->name."</td>";
                        echo "<td>".$row->mobile."</td>";
                        echo "<td style='display:none;'>".$row->email."</td>";
                        echo "<td style='display:none;'>".$row->address."</td>";
                        echo "<td style='display:none;'>".$row->country."</td>";
                        echo "<td style='display:none;'>".$row->province."</td>";
                        echo "<td>".$row->district."</td>";
                        echo "<td>".$row->area."</td>";
                        echo '<td>
                              <div class="row row-icons text-center">
                                 <div class="col"><i class="fa fa-hand-o-up selectPartner" name="selectPartner" aria-hidden="true" value="'.$row->partner_id.'"></i></div>
                              </div>
                              </td>';
                        $i++;
                        }
                        ?>  
               </tbody>

我正在尝试将图像添加到表格行。但是在网站运行时图像不会出现。在检查元素中,我看到baseurl不能正常工作。我认为这是串联错误。如何解决该问题?

3 个答案:

答案 0 :(得分:2)

就像处理其他变量一样,您可以中断字符串并插入代码:

echo '<td><img src="' . base_url() . 'assets/img/erplanka/profilepic.png" class="img-fluid img-thumbnail profimg"></td>';

我不知道base_url()是否提供'/',如果不是,您还应该在'assets'之前添加'/'

答案 1 :(得分:0)

您必须按以下步骤更改该部分:

<?php
    foreach($data as $row) {
      //........ other section of code
      $image = base_url() . 'assets/img/erplanka/profilepic.png';
      echo '<td><img src="' . $image. '"' . 'class="img-fluid img-thumbnail profimg"></td>';
    }

答案 2 :(得分:0)

看起来与base_url()函数所在的行是错误的。

echo '<td><img src="<?php echo base_url()?>assets/img/erplanka/profilepic.png" class="img-fluid img-thumbnail profimg"></td>';

应该是

echo '<td><img src="' . base_url() . '/assets/img/erplanka/profilepic.png" class="img-fluid img-thumbnail profimg"></td>';