简体   繁体   English

使用 PHP 生成的 HTML 表

[英]HTML table generated with PHP

function destinations(){
    global $db;

    $numri1 = $db->query("SELECT * FROM destinations WHERE direction='1';");

        $i = 1;
        while ($row = mysql_fetch_array($numri1)) {
            if ($i % 2 != "0") # An odd row
              $rowColor = "bgC1";
            else # An even row
              $rowColor = "bgC2";

            $direction1 .= '<tr class="'.$rowColor.'">
                                <td>'.$i.'</td>
                                <td>'.$row['name'].'</td>
                            </tr>';
        $i++;
        }


$table1 =  '<table width="30%" style="margin:10px 10px 0 10px;" class="extra" cellspacing="1" cellpadding="5" border="0" >
            <tr class="bgC3" style="font-weight:bold;>
                <td>asd</td>
                <td>Qytetet domestike</td>
            </tr>
            '.$direction1.'
            </table>';

        return $table1;
}

There must be a small problem with this because when its displayed in browser it doest show this:这肯定有一个小问题,因为当它显示在浏览器中时,它不会显示:

        <tr class="bgC3" style="font-weight:bold;>
            <td>asd</td>
            <td>Qytetet domestike</td>
        </tr>

well, it shows it but it replaces the values the "asd" and "Qytetet domestike"!好吧,它显示了它,但它替换了“asd”和“Qytetet domestike”的值!

You're missing a quote at the end of your style attribute.您在style属性的末尾缺少引号。

Change:改变:

<tr class="bgC3" style="font-weight:bold;>

To:至:

<tr class="bgC3" style="font-weight:bold;">
                                         ^

See this fiddle ?看到这个小提琴了吗? No table displayed!没有显示表格! Now have a look at this fiddle .现在看看这个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM