dsfs23434
2017-08-14 05:08
浏览 438
已采纳

如何在PHP代码中使用<td>里面的div标签

I want to know how should we use div tags inside a table in PHP code. This is my code. Please tell me how to use it properly.

<tbody>
    <?php
    $result = mysqli_query($conn,$sql);
    while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {  

        echo "<tr>

        <td>{$row['id']}</td>
        <td><img  width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
        <td>{$row['item_name']}</td>
        <td>{$row['description']}</td>
        <td>{$row['quantity']}</td>
        <td>echo '<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">

            <div class="c-input-group c-spinner">
                <input type="text" class="form-control c-item-1" value="1">
                <div class="c-input-group-btn-vertical">
                    <button class="btn btn-default" type="button" data_input="c-item-1">
                        <i class="fa fa-caret-up"></i>
                    </button>
                    <button class="btn btn-default" type="button" data_input="c-item-1">
                        <i class="fa fa-caret-down"></i>
                    </button>
                </div>
            </div>
        </div> 
        </td>';                                                 
        <td> <button>submit</button>  </td>

        </tr>";


    }?>
</tbody>

I have tried using inverted comma's and braces but still, it shows error. What needs to be done here?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongtuoji5396 2017-08-14 05:15
    已采纳

    You can write the div inside table. Don't put all table inside php tag. remove html outside the <?php ?> php code. after that whenever you want to echo any value just used the php.

    Customize your code like below,

    <table>
        <tbody>
            <?php
            $result = mysqli_query($conn, $sql);
            while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
                ?>
                <tr>
                    <td><?php echo $row['id']; ?></td>
                    <td><img  width='90px' height='90px' src='imageView.php?id=<?php echo $row["id"]; ?>' /> </td>
                    <td><?php echo $row['item_name']; ?></td>
                    <td><?php echo $row['description']; ?></td>
                    <td><?php echo $row['quantity']; ?></td>
                    <td>
                        <div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
    
                            <div class="c-input-group c-spinner">
                                <input type="text" class="form-control c-item-1" value="1">
                                <div class="c-input-group-btn-vertical">
                                    <button class="btn btn-default" type="button" data_input="c-item-1">
                                        <i class="fa fa-caret-up"></i>
                                    </button>
                                    <button class="btn btn-default" type="button" data_input="c-item-1">
                                        <i class="fa fa-caret-down"></i>
                                    </button>
                                </div>
                            </div>
                        </div> 
                    </td>                                             
                    <td> <button>submit</button>  </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dreamice2013 2017-08-14 05:24

    Within a double quote you can use a single quote

    <tbody>
                                             <?php
                                              $result = mysqli_query($conn,$sql);
                                                   while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {  
    
                                                echo "<tr>
                                                   
                                                    <td>{$row['id']}</td>
                                                    <td><img  width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
                                                    <td>{$row['item_name']}</td>
                                                     <td>{$row['description']}</td>
                                                    <td>{$row['quantity']}</td>
                                                     <td><div class='col-md-1 col-sm-3 col-xs-6 c-cart-qty'>
                                                          
                                                            <div class='c-input-group c-spinner'>
                                                             <input type='text' class='form-control c-item-1' value='1'>
                                                               <div class='c-input-group-btn-vertical'>
                                                                 <button class='btn btn-default' type='button' data_input='c-item-1'>
                                                                   <i class='fa fa-caret-up'></i>
                                                                  </button>
                                                                 <button class='btn btn-default' type='button' data_input='c-item-1'>
                                                                    <i class='fa fa-caret-down'></i>
                                                                  </button>
                                                                </div>
                                                           </div>
                                                         </div> 
                                                     </td>;                                                 
                                                    <td> <button>submit</button>  </td>
                                    
                                                  </tr>";
                                               
                                               
                                                }?>
                                            </tbody>

    </div>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题