我目前所做的是我使用AJAX在id为searchresults的div中显示搜索记录的所有列,然后我给出一个打印选项来打印这些记录。现在我希望能够选择一组列(为此我已经为所有列提供了一个复选框)并仅打印选定的列。我可以在php文件中获取所选列,但如何从所选列值中构建查询。我的意思是可以有这么多不同的组合。代码到现在为止..
<?php
echo ' <table border="1">
<tr>
<td class="lab searchtableheader" style="color:#cd0000; padding:5px;"><input type="checkbox" name="print" value="facultyname" /><br>FACULTY</td>
<td class="lab searchtableheader" style="color:#de0000; padding:5px;"><input type="checkbox" name="print" value="departmentname" /><br>DEPT.</td>
<td class="lab searchtableheader" style="color:#ef0000; padding:5px;"><input type="checkbox" name="print" value="coursename" /><br>COURSE</td>
<td class="lab searchtableheader" style="color:#ff0000; padding:5px;"><input type="checkbox" name="print" value="year" /><br>YEAR </td>
<td class="lab searchtableheader" style="color:#f50853; padding:5px;"><input type="checkbox" name="print" value="semester" /><br>SEM. </td>
<td class="lab searchtableheader" style="color:#f5087e; padding:5px;"><input type="checkbox" name="print" value="studentname" /><br>NAME </td>
<td class="lab searchtableheader" style="color:#f508dd; padding:5px;"><input type="checkbox" name="print" value="enrollment" /><br>ENROLL. </td>
<td class="lab searchtableheader" style="color:#c108f5; padding:5px;"><input type="checkbox" name="print" value="courseseatcategory" /><br>SEAT CATEGORY</td>
<td class="lab searchtableheader" style="color:#7e08f5; padding:5px;"><input type="checkbox" name="print" value="gender" /><br>GENDER </td>
<td class="lab searchtableheader" style="color:#3f08f5; padding:5px;"><input type="checkbox" name="print" value="dob" /><br>D.O.B</td>
<td class="lab searchtableheader" style="color:#2f95f4; padding:5px;"><input type="checkbox" name="print" value="religion" /><br>RELIGION </td>
<td class="lab searchtableheader" style="color:#9f4ef0; padding:5px;"><input type="checkbox" name="print" value="category" /><br>CATEGORY </td>
<td class="lab searchtableheader" style="color:#ee4ef0; padding:5px;"><input type="checkbox" name="print" value="country" /><br>COUNTRY </td>
<td class="lab searchtableheader" style="color:#f70767; padding:5px;"><input type="checkbox" name="print" value="state" /><br>STATE </td>
<td class="lab searchtableheader" style="color:#ef4ef0; padding:5px;"><input type="checkbox" name="print" value="internal" /><br>INTERNAL </td>
<td class="lab searchtableheader" style="color:#2e95f3; padding:5px;"><input type="checkbox" name="print" value="ph" /><br>PH </td>
<td class="lab searchtableheader" style="color:#7e08f1; padding:5px;"><input type="checkbox" name="print" value="dor" /><br>D.O.R </td>
<td class="lab searchtableheader" style="color:#f508aa; padding:5px;"><input type="checkbox" name="print" value="supervisior" /><br>SUPERVISOR </td>
<td class="lab searchtableheader" style="color:#ff0000; padding:5px;"><input type="checkbox" name="print" value="cosupervisor" /><br>COSUPERVISOR </td>
<td class="lab searchtableheader" style="color:#9f4ef0; padding:5px;"><input type="checkbox" name="print" value="titleofthesis" /><br>TITLE of THESIS</td>
<td class="lab searchtableheader" style="color:#2f95f4; padding:5px;"><input type="checkbox" name="print" value="mou" /><br>MOU </td>
<td class="lab searchtableheader" style="color:#7e08f5; padding:5px;"><input type="checkbox" name="print" value="mouinstitute" /><br>MOU INSTITUTE </td>
</tr> ';?>
要打印的JavaScript:
function printDiv()
{
var divToPrint=document.getElementById('searchresults');
newWin= window.open("");
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}
答案 0 :(得分:1)
首先,您需要将name =“print”更改为name =“print []”,以便php可以获取所有选定的值。
无论您是使用帖子还是继续提交信息,您都需要循环播放所发送的值。信息将在打印数组中。
$prn = $_POST['print'];
$sql = "SELECT ";
$flds = "";
foreach( $prn as $p ) {
if( $flds != "" ) $flds .= ",";
$flds .= $p
}
$sql .= $flds . " FROM ....
请注意代码未经测试,但它应该为您提供一个起点