【转】PHP查询MySql数据库,将结果用表格输出实例
[
2019/03/22 15:41 | by 吕进 | Via 本站原创 ]

在用PHP开发网站时,MySql数据库查询结果用表格输出,对于初学PHP程序开发的同学可能有一些难度。
本文以实例形式演示了PHP查询MySql数据库,并将结果用表格输出的功能,希望对大家的PHP编程有所帮助。
本文以实例形式演示了PHP查询MySql数据库,并将结果用表格输出的功能,希望对大家的PHP编程有所帮助。
<strong><span style="font-size:18px;">
<?php
//PHP查询MySql数据库,将结果用表格输出
function ShowTable($table_name){
$conn=mysql_connect("localhost","root","toor");
if(!$conn){
echo "连接失败";
}
mysql_select_db("test",$conn);
mysql_query("set names utf8");
$sql="select * from $table_name";
$res=mysql_query($sql,$conn);
$rows=mysql_affected_rows($conn);//获取行数
$colums=mysql_num_fields($res);//获取列数
echo "test数据库的"."$table_name"."表的所有用户数据如下:<br/>";
echo "共计".$rows."行 ".$colums."列<br/>";
echo "<table><tr>";
for($i=0; $i < $colums; $i++){
$field_name=mysql_field_name($res,$i);
echo "<th>$field_name</th>";
}
echo "</tr>";
while($row=mysql_fetch_row($res)){
echo "<tr>";
for($i=0; $i<$colums; $i++){
echo "<td>$row[$i]</td>";
}
echo "</tr>";
}
echo "</table>";
}
ShowTable("test1");
?></span></strong>
<?php
//PHP查询MySql数据库,将结果用表格输出
function ShowTable($table_name){
$conn=mysql_connect("localhost","root","toor");
if(!$conn){
echo "连接失败";
}
mysql_select_db("test",$conn);
mysql_query("set names utf8");
$sql="select * from $table_name";
$res=mysql_query($sql,$conn);
$rows=mysql_affected_rows($conn);//获取行数
$colums=mysql_num_fields($res);//获取列数
echo "test数据库的"."$table_name"."表的所有用户数据如下:<br/>";
echo "共计".$rows."行 ".$colums."列<br/>";
echo "<table><tr>";
for($i=0; $i < $colums; $i++){
$field_name=mysql_field_name($res,$i);
echo "<th>$field_name</th>";
}
echo "</tr>";
while($row=mysql_fetch_row($res)){
echo "<tr>";
for($i=0; $i<$colums; $i++){
echo "<td>$row[$i]</td>";
}
echo "</tr>";
}
echo "</table>";
}
ShowTable("test1");
?></span></strong>
一个form表单有两个按钮,分别提交到不同的页面
[
2019/01/11 09:56 | by 吕进 | Via 本站原创 ]

直接上代码
h5中新增的 formaction属性,
带有两个提交按钮的表单(不同的 action 值):
<script language="javascript">
function chaxun(){
document.MyForm.action="#";
document.MyForm.submit();
}
function daochu(){
document.forms.MyForm.action="daochu.php";
document.forms.MyForm.submit();
}
</script>
<form method="post" id="MyForm">
<input type="button" name="btn1" value="查询" onclick="chaxun();">
<input type="button" name="btn2" value="导出" onclick="daochu();">
</form>
function chaxun(){
document.MyForm.action="#";
document.MyForm.submit();
}
function daochu(){
document.forms.MyForm.action="daochu.php";
document.forms.MyForm.submit();
}
</script>
<form method="post" id="MyForm">
<input type="button" name="btn1" value="查询" onclick="chaxun();">
<input type="button" name="btn2" value="导出" onclick="daochu();">
</form>
h5中新增的 formaction属性,
带有两个提交按钮的表单(不同的 action 值):
<form action="demo_form.php" method="post">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" /><br />
<input type="submit" formaction="demo_admin.php" value="系统管理" />
</form>
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" value="Submit" /><br />
<input type="submit" formaction="demo_admin.php" value="系统管理" />
</form>
EXCEL VBA中Target.Address语句用法
[
2018/12/26 10:07 | by 吕进 | Via 本站原创 ]

Target.Address 返回的是文本型式。
Target.Address = Cells(4, 2).Address【更适配合match函数写动态单元格地址】
或
Target.Address = “$B$4”
Target.Address = Cells(4, 2).Address【更适配合match函数写动态单元格地址】
或
Target.Address = “$B$4”
推广:重庆泰萌(U萌商城)
[
2018/12/08 15:23 | by 吕进 | Via 本站原创 ]

JS自适应高度,其实就是设置iframe的高度,使其等于内嵌网页的高度,从而看不出来滚动条和嵌套痕迹。对于用户体验和网站美观起着重要作用。
如果内容是固定的,那么我们可以通过CSS来给它直接定义一个高度,同样可以实现上面的需求。当内容是未知或者是变化的时候。这个时候又有几种情况了。
iframe内容未知,高度可预测
这个时候,我们可以给它添加一个默认的CSS的min-height值,然后同时使用JavaScript改变高度。常用的兼容代码有:
......
内容宽度变化的iframe高度自适应
如果内容是固定的,那么我们可以通过CSS来给它直接定义一个高度,同样可以实现上面的需求。当内容是未知或者是变化的时候。这个时候又有几种情况了。
iframe内容未知,高度可预测
这个时候,我们可以给它添加一个默认的CSS的min-height值,然后同时使用JavaScript改变高度。常用的兼容代码有:
// document.domain = "caibaojian.com";
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
}
}
};
window.onload = function () {
setIframeHeight(document.getElementById('external-frame'));
};
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
}
}
};
window.onload = function () {
setIframeHeight(document.getElementById('external-frame'));
};
......
内容宽度变化的iframe高度自适应