0

如何修改下面的代码以动态地将我的 SQL 查询结果生成到一个想要下面示例表的表中?(每个表格行 2 个项目)

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
    function test() {
        try {
            alert("running function test")
        var cn      = new ActiveXObject("ADODB.Connection")
        var rs      = new ActiveXObject("ADODB.Recordset")
        var sql     = "SELECT * FROM tbl_rssims"
        var db      = "G:\\AS\\Asf\\ASF\\RSSIMS\\db\\rssims.mdb"

        cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + db + "")
        rs.Open(sql, cn, 1, 3)

        var html    =  '<!DOCTYPE html>\n'
            html    +=  '<html>\n'
            html    +=  '<head>\n'
            html    +=  '<table style="border: none; table-layout: fixed; width: 100%; text-align: left;" cellpadding="0" cellspacing="0">\n'

            //<!-- WRITE FIELD VALUES -->
            while (!rs.eof) {
                html += '<tr>\n';
                for (var c = 0; c < rs.fields.count; ++c) {
                    html += '<td>' + rs.fields(c).value + '</td>\n'
                }//end of for
                html += '</tr>\n'
                rs.movenext
            }//end of while
            html += '</table>'
            window.open('','').document.write(html)

        rs.close
        cn.close
    }//end of try
    catch(e) {
        alert(e.description)
    }
}//end of function

</script>
</head>
<body>
    <b>Example:</b>
    <table style="border: none; table-layout: fixed; width: 100%; text-align: left;" cellpadding="0" cellspacing="0">
        <tr>
            <td>Mr. Ronald McDonald<br>Chief Executive Officer<br>The Hudson Bay Corporation<br>123 Yahoo Street<br>Toronto, Ontario<br>Canada</td>
            <td>Mr. Steve Marin<br>Chief Executive Officer<br>General Motors<br>456 Don Mills Street<br>Toronto, Ontario<br>Canada</td>
        </tr>
    </table>
    <input onclick="test()" type="button" value="button" id="button">
</body>
</html>
4

2 回答 2

0

这个怎么样:

html += '<tr><td>' + rs.GetString(2, -1, '<br>', '</td><td>', '') + '</td></tr>';

你想要<br>在每一列</td><td>之间,以及每一行之间。

于 2012-11-15T20:53:09.377 回答
0

尝试这样的事情..

<php?
$query='select * from table_name';
$result=mysql_query($query);
?>
<table>
<tr>
<th>ID </th>
<th>Name</th>
</tr>
<?php
while($row=mysql_fetch_assoc($result)){
    echo '<tr>
    <td align="center">'.$row['id'].'-'.$row['sID'].'</td>
    <td align="center">'.$row['name'].'</td>
    </tr>';
}
?>
</table>
于 2012-11-15T21:02:19.697 回答