mysql — Как напечатать (экспортировать) результаты поиска в MS-Word (PHP)

Я пытаюсь экспорт в MS Word результат поиска с помощью PHP но мой код не работает.

Вот мой код:

<?php
error_reporting(0);
include("configsample.php");
?>
<html>
<title>Home</title>
<head>
<meta charset="UTF-8">
<title>Flat Login Form</title>
</head>
<body>

<form class="login-form" method="post" action="viewstucon.php">
<select class="s" id="course" name="course">
<option value="">Select Course</option>
<option value="Bachelor of Secondary Education"<?php if (!(strcmp("Bachelor of Secondary Education", $_POST["course"]))) {echo "selected=\"selected\"";} ?>>Bachelor of Secondary Education</option>
<option value="Bachelor of Science in Automotive Technology"<?php if (!(strcmp("Bachelor of Science in Automotive Technology", $_POST["course"]))) {echo "selected=\"selected\"";} ?>>Bachelor of Science in Automotive Technology</option>
<option value="Bachelor of Science in Electrical Technology"<?php if (!(strcmp("Bachelor of Science in Electrical Technology", $_POST["course"]))) {echo "selected=\"selected\"";} ?>>Bachelor of Science in Electrical Technology</option>
</select>
<input class="sy" name="from" type="text" id="from" size="10" width="100%" value="<?php echo $_REQUEST["from"]; ?>" placeholder="From"/>
<input class="sy" name="to" type="text" id="to" size="10" width="100%" value="<?php echo $_REQUEST["to"]; ?>" placeholder="To"/>
<button type="submit" name="submit" >Filter</button>

</form>

<table width="100%" border="1" style="border: 1px solid #999999; border-collapse: collapse; margin:0 auto; background:#ffffff; border-radius:20px;">
<tr style="background:#3366cc; color:#ffffff; font:normal 15px Tahoma; height:40px;">
<th>Research Title</th>
<th>Year</th>
<th>Proponent(s)</th>
</tr>

<?php
if ($_REQUEST["course"]<>'') {
$search_course = " AND restu_course='".mysql_real_escape_string($_REQUEST["course"])."'";
}
if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year BETWEEN '".mysql_real_escape_string($_REQUEST["from"])."' AND '".mysql_real_escape_string($_REQUEST["to"])."'".$search_course;
} else if ($_REQUEST["from"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year = '".mysql_real_escape_string($_REQUEST["from"])."'".$search_course;
} else if ($_REQUEST["to"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year = '".mysql_real_escape_string($_REQUEST["to"])."'".$search_course;
} else {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_id>0".$search_course;
}

$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result))
{
echo'<tr style="font:normal 12px Tahoma; color:#333333;">
<td style="padding:10px;">'.$row['restu_title'].'</a></td>
<td style="padding:10px;">'.$row['restu_year'].'</td>
<td style="padding:10px;">'.$row['restu_by'].'</td>
</tr>';
}
}else
{
echo'<tr><td colspan="5">No results found.</td>';
}
?>
</table>
<a href="print.php">Export to Word</a>
</body>
</html>

Вот код print.php:

<?php
error_reporting(0);
include("configsample.php");
?>
<?php
HEADER("Content-Type: application/msword");
HEADER("Content-Disposition: attachment; filename=database_dump.doc");
HEADER("Pragma: no-cache");
HEADER("Expires: 0");if ($_REQUEST["course"]<>'') {
$search_course = " AND restu_course='".mysql_real_escape_string($_REQUEST["course"])."'";
}

if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year BETWEEN '".mysql_real_escape_string($_REQUEST["from"])."' AND  '".mysql_real_escape_string($_REQUEST["to"])."'".$search_course;
} else if ($_REQUEST["from"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year >= '".mysql_real_escape_string($_REQUEST["from"])."'".$search_course;
} else if ($_REQUEST["to"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year = '".mysql_real_escape_string($_REQUEST["to"])."'".$search_course;
} else {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_id>0".$search_course;
}

echo"<table border='1' width='100%' style='border: 1px solid #999999; border-collapse: collapse; margin:0 auto; background:#ffffff; border-radius:20px;'>
<tr style='background:#3366cc; color:#ffffff; font:normal 15px Tahoma; height:40px;'>
<th>Research No.</th>
<th>Course</th>
<th>Year</th>
</tr>";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result)) {

echo'<tr style="font:normal 12px Tahoma; color:#333333;">
<td style="padding:10px;">'.$row['restu_id'].'</td>
<td style="padding:10px;">'.$row['restu_course'].'</td>
<td style="padding:10px;">'.$row['restu_year'].'</td>
</tr>';
}
echo"</table>";
}
?>

Проблема здесь в том, что он экспортирует весь список таблиц, а не только результаты поиска.

0

Решение

Ваш массив $ _REQUEST в print.php пуст, страница не знает параметров поиска.
Вы можете попробовать передать параметр через метод GET следующим образом:

Замена

<a href="print.php">Export to Word</a>

от

<a href="print.php?<?php
echo "course=".$_REQUEST["course"]."&from=".$_REQUEST["from"]."&to=".$_REQUEST["to"];
?>">Export to Word</a>

в первом файле

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]