html中触发php代码
<div><formname="form1"method="post"action=""><inputname="button"type="reset"value="Fl...
<div>
<form name="form1" method="post" action="">
<input name="button" type="reset" value="Flood" onclick="pstdatasearch.php"/>
</form>
</div>
<?php
// Get the search variable from URL
require_once('config.php');
//connect to your database ** EDIT REQUIRED HERE **
$connection=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //(host, username, password)
//specify database ** EDIT REQUIRED HERE **
mysql_select_db(DB_DATABASE,$connection) or die("Unable to select database"); //select which database we're using
// Build SQL Query
$result = mysql_query ("SELECT * FROM pstdisaster Where type = 'Flood'",$connection); // EDIT HERE and specify your table and field names for the SQL query
print "<table border='1'>";
print "<th align = 'center'>Name</th>";
print "<th align = 'center'>Type</th>";
print "<th align = 'center'>Date</th>";
print "<th align = 'center'>Location</th>";
print "<th align = 'center'>Level</th>";
print "<th align = 'center'>Government reaction</th>";
print "<th align = 'center'>Public response</th>";
print "<th align = 'center'>Sourse</th>";
print "<th align = 'center'>Damages</th>";
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
//echo "$count.) $title $title2 $title3 $title4 $title5 $title6 $title7 $title8 $nbsp; $title9" ;
// (5) Print out each element in $row, that is, print the values of
print "<tr> \n";
print "<td align = 'center'>{$row["name"]}</td>";
print "<td align = 'center'>{$row["type"]}</td>";
print "<td align = 'center'>{$row["date"]}</td>";
print "<td align = 'center'>{$row["location"]}</td>";
print "<td align = 'center'>{$row["level"]}</td>";
print "<td align = 'center'>{$row["Reaction"]}</td>";
print "<td align = 'center'>{$row["Responses"]}</td>";
print "<td align = 'center'>{$row["Sourse"]}</td>";
print "<td align = 'center'>{$row["damages"]}</td> <br> </n>";
print "</tr> \n";
// Print a carriage return to neaten the output
print "\n";
}
?>
我要的效果是 点击按钮 后再出现表单 而且之后还有多个按钮 点其他按钮会触发其他代码 覆盖之前输出的表格 展开
<form name="form1" method="post" action="">
<input name="button" type="reset" value="Flood" onclick="pstdatasearch.php"/>
</form>
</div>
<?php
// Get the search variable from URL
require_once('config.php');
//connect to your database ** EDIT REQUIRED HERE **
$connection=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //(host, username, password)
//specify database ** EDIT REQUIRED HERE **
mysql_select_db(DB_DATABASE,$connection) or die("Unable to select database"); //select which database we're using
// Build SQL Query
$result = mysql_query ("SELECT * FROM pstdisaster Where type = 'Flood'",$connection); // EDIT HERE and specify your table and field names for the SQL query
print "<table border='1'>";
print "<th align = 'center'>Name</th>";
print "<th align = 'center'>Type</th>";
print "<th align = 'center'>Date</th>";
print "<th align = 'center'>Location</th>";
print "<th align = 'center'>Level</th>";
print "<th align = 'center'>Government reaction</th>";
print "<th align = 'center'>Public response</th>";
print "<th align = 'center'>Sourse</th>";
print "<th align = 'center'>Damages</th>";
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
//echo "$count.) $title $title2 $title3 $title4 $title5 $title6 $title7 $title8 $nbsp; $title9" ;
// (5) Print out each element in $row, that is, print the values of
print "<tr> \n";
print "<td align = 'center'>{$row["name"]}</td>";
print "<td align = 'center'>{$row["type"]}</td>";
print "<td align = 'center'>{$row["date"]}</td>";
print "<td align = 'center'>{$row["location"]}</td>";
print "<td align = 'center'>{$row["level"]}</td>";
print "<td align = 'center'>{$row["Reaction"]}</td>";
print "<td align = 'center'>{$row["Responses"]}</td>";
print "<td align = 'center'>{$row["Sourse"]}</td>";
print "<td align = 'center'>{$row["damages"]}</td> <br> </n>";
print "</tr> \n";
// Print a carriage return to neaten the output
print "\n";
}
?>
我要的效果是 点击按钮 后再出现表单 而且之后还有多个按钮 点其他按钮会触发其他代码 覆盖之前输出的表格 展开
3个回答
展开全部
<div id=info></div>
<input type=button onclick=pstdatasearch.php?act=1 />
<input type=button onclick=pstdatasearch.php?act=2 />
<?php
if(_GET('act')==1){
document.getElementById('info').innerHTML = 'aaaaaaaaaa';
}else if(_GET('act')==2){
document.getElementById('info').innerHTML = 'bbbbbbbbbbbbbb';}
?>
<input type=button onclick=pstdatasearch.php?act=1 />
<input type=button onclick=pstdatasearch.php?act=2 />
<?php
if(_GET('act')==1){
document.getElementById('info').innerHTML = 'aaaaaaaaaa';
}else if(_GET('act')==2){
document.getElementById('info').innerHTML = 'bbbbbbbbbbbbbb';}
?>
追问
dcument.get是做什么用的? 我改成这样了 但是点击按钮 没任何动作 if之后语句不运行
<?php
$a=$_GET['act'];
if($a==1){ 原代码段}
else if($a==2){原代码段}
追答
document.getElementById('info').innerHTML
是javascript里的代码,作用是找到网页中叫"info"的元素,并更改它的内容。
代码修改了下,你先执行我这段看看有没有问题,如果OK,则说明可行。
展开全部
设置一个公用DIV id=show.用JS的onclick触发后用AJAX去取得PHP内容,再用document.getElementById("show").innerHTML=返回的内容...这样就行了,这样当你每次触发,DIV里的内容都会改变...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询