从phpmyadmin数据库插入数据到同一php页面中的excel

时间:2019-02-13 10:35:16

标签: php mysql

我有一个PHP代码,可在其中搜索数据库中的数据并将其显示在同一页面上。我想在同一PHP页面上下载以excel格式显示数据的数据。就像我单击搜索按钮时一样,它将显示数据以及将数据下载到excel文件中。 我需要代码,以便可以将数据导出到excel。我是初学者级程序员。所以请帮帮我。 谢谢。

<?Php
//ini_set('display_errors', true);//Set this display to display  all erros while testing and developing the script
error_reporting(0);// With this no error reporting will be there
include "config_1.php";



echo "<center><br><br><br>
<form  method=post action='zonebagnan.php' ><input type=hidden  name=todo value=search>
<input type=text  name=search_text value='$search_text' ><br><br>
<input type=hidden  name=todo2 value=search2>
<input type=date  name=search_text2 value='$search_text2' ><br><br>
<input type=hidden  name=todo3 value=search3>
<input type=date  name=search_text3 value='$search_text3' ><br><br>

<input type=submit value=Search><br>


</form>
</center>
";

$todo=$_POST['todo'];
$search_text=$_POST['search_text'];
$todo2=$_POST['todo2'];
$search_text2=$_POST['search_text2'];
$todo3=$_POST['todo3'];
$search_text3=$_POST['search_text3'];

if(strlen($serch_text) > 0){
if(!ctype_alnum($search_text)){
echo "Data Error";
exit;
}
}
if(isset($todo) and $todo=="search"){

$type=$_POST['type'];

$search_text=ltrim($search_text);
$search_text=rtrim($search_text);

    if($type<>"any"){
$query="select * from formbagnan where zone='$search_text' and date between '$search_text2' and '$search_text3' ";
$count=$dbo->prepare($query);
$count->execute();
$no=$count->rowCount();

echo "

 <table class='border' style='text-align:center;'  width='900'>";

 echo "</td><td>";

echo "<tr><th>Name</th><th>Parent Name</th><th>Faculty Name</th><th>Roll</th><th>Address</th><th>Zone</th><th>Pin</th><th>Phone</th><th>Another Phone</th><th>Teacher Name 1</th><th>Teacher Phone 1</th><th>Teacher Address 1</th><th>Teacher Name 2</th><th>Teacher Phone 2</th><th>Teacher Address 2</th><th>Teacher Name 3</th><th>Teacher Phone 3</th><th>Teacher Address 3</th><th>D.O.B</th><th>Gender</th><th>School/College Name</th><th>Qualification</th><th>Stream</th><th>Year</th><th>Course Name</th>
<th>Date</th></tr>";
foreach ($dbo->query($query) as $row){

echo "<tr><td>$row[name]</td><td>$row[pname]</td><td>$row[fn]</td><td>$row[roll]</td><td>$row[address]</td><td>$row[zone]</td><td>$row[pin]</td><td>$row[phone]</td><td>$row[phone2]</td><td>$row[tn]</td><td>$row[tp]</td><td>$row[ta]</td><td>$row[tn2]</td><td>$row[tp2]</td><td>$row[ta2]</td><td>$row[tn3]</td><td>$row[tp3]</td><td>$row[ta3]</td><td>$row[dob]</td><td>$row[gender]</td><td>$row[instn]</td><td>$row[qual]</td><td>$row[stream]</td><td>$row[year]</td><td>$row[cn]</td><td>$row[date]</td>
</tr>";
}
echo "</table>";

echo "</td></tr></table>";
        }
else {
echo " No records found ";
}
}
 ?>

0 个答案:

没有答案