mysql - How to print (export) to MS-Word search result (PHP) -


i'm trying export ms word search result using php code not working.

here code:

<?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 = " , restu_course='".mysql_real_escape_string($_request["course"])."'"; } if ($_request["from"]<>'' , $_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." restu_year between '".mysql_real_escape_string($_request["from"])."' , '".mysql_real_escape_string($_request["to"])."'".$search_course; } else if ($_request["from"]<>'') { $sql = "select * ".$settings["data_table"]." restu_year = '".mysql_real_escape_string($_request["from"])."'".$search_course; } else if ($_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." restu_year = '".mysql_real_escape_string($_request["to"])."'".$search_course; } else { $sql = "select * ".$settings["data_table"]." 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 word</a> </body> </html> 

here print.php code:

<?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 = " , restu_course='".mysql_real_escape_string($_request["course"])."'";    }  if ($_request["from"]<>'' , $_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." restu_year between '".mysql_real_escape_string($_request["from"])."' ,  '".mysql_real_escape_string($_request["to"])."'".$search_course; } else if ($_request["from"]<>'') { $sql = "select * ".$settings["data_table"]." restu_year >= '".mysql_real_escape_string($_request["from"])."'".$search_course; } else if ($_request["to"]<>'') { $sql = "select * ".$settings["data_table"]." restu_year = '".mysql_real_escape_string($_request["to"])."'".$search_course; } else { $sql = "select * ".$settings["data_table"]." 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>"; }    ?> 

the problem here exports table list instead of search result only.

your $_request array in print.php empty, page didn't know parameters of search. can try pass parameter via method way :

replacing

<a href="print.php">export word</a> 

by

<a href="print.php?<?php      echo "course=".$_request["course"]."&from=".$_request["from"]."&to=".$_request["to"]; ?>">export word</a> 

in first file


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -