<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
 */
require "global.php";
$sqlcode=stripslashes($_POST["sqlcode"]);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="css/admincp.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
  <div class="floattop">
    <div class="itemtitle"><h3>SQL工具</h3>
      <ul class="tab1">
        <li class="current"><a href="links.php"><span>SQL工具</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>
<table class="tb tb2 " id="tips">
<form id="form1" name="form1" method="post" action="?action=runsql">
  <tr><th  class="partition" colspan="10">SQL工具</th></tr>
  <tr>
    <td align="left" width="50"></td>
    <td align="left">
      <textarea name="sqlcode" rows="6" style="width:80%;"><?php echo $sqlcode?></textarea>    </td>
  </tr>
  <tr>
    <td align="left" width="50"></td>
    <td align="left"><input type="submit" name="Submit" value="提交" /></td>
  </tr>
 </form> 
</table>
	<?php
	$action=$_GET["action"];
	if ($action=="runsql")
	{
	 $result=mysql_query($sqlcode);
	 $data=array();
	 while ($r=mysql_fetch_array($result,MYSQL_ASSOC)) $data[]=$r;
	}
	?>
	
<?php if($data){?>
<table class="tb tb2 " id="tips">
	<tr>
	<?php foreach($data[0] as $k=>$v){?>
		<th><?=$k?></th>
	<?php }?>
	</tr>
	<?php foreach($data as $row){?>
		<tr>
			<?php foreach($row as $v){?>
				<td><?=$v?></td>
			<?php }?>
		</tr>
	<?php }?>
</table>
<?php
}
?>
