每秒使用后添加

时间:2014-11-25 19:53:00

标签: php jquery tr

我有PHP代码,使用<td>标记从数据库中提取图像。我想在行中显示两张图片,建议如何使用jQuery在每秒<tr>之后添加<td>

public function homepage_gall($panel){

    //Fetching photos from database,to create photo gallery called in homepage.php
    $sql="SELECT name FROM photos LIMIT 6";
    $this->query($sql);

    while($row=$this->result->fetch_array(MYSQLI_ASSOC)){
        $this->name=$row['name'];

    // Making different path,depends on place where function is called,panel.php or homepage.php
        if($panel){

        echo "<td><img src=\"../uploaded_images/".$this->name."\"/></td>";
                }
        else{


        echo "<td><img src=\"uploaded_images/".$this->name."\"/></td>";

         }
        }
   }

1 个答案:

答案 0 :(得分:0)

我不知道你为什么要在这上面使用jQuery,但我会添加一个表并用PHP处理所有tr和td。如果您需要,请用以下内容替换整个代码:

public function homepage_gall($panel) {
    //Fetching photos from database,to create photo gallery called in homepage.php
    $sql = "SELECT name FROM photos LIMIT 6";
    $this->query($sql);
    echo '<table><tr>';
    $i = 0;
    while ($row = $this->result->fetch_array(MYSQLI_ASSOC)) {
        $i++;
        $this->name=$row['name'];
        // Making different path,depends on place where function is called,panel.php or homepage.php
        if ($i % 2 === 0) {
            echo '</tr><tr>';
        }
        if ($panel) {
            echo "<td><img src=\"../uploaded_images/".$this->name."\"/></td>";
        } else {
            echo "<td><img src=\"uploaded_images/".$this->name."\"/></td>";
        }
    }
    echo '</tr></table>';
}