Can php code execute while creation of pdf using tcpdf? - php

I m working on module in which i have to make pdf from php page. I m Using tcpdf for that but m facing one problem that file contain some mysql queries and php coding which is not executed by pdf page.
$prn_no = $_POST['prn_no'];
$current_sem = $_POST['current_sem'];
$qr_fetch_sem_res_id = mysql_query("SELECT * FROM table1 WHERE ((prn='$prn_no') AND (semisterName='$current_sem'))")or die(mysql_error());
$qr_fetch_sem_result_ans = mysql_fetch_array($qr_fetch_sem_res_id);
<tr>
<td colspan="11" align="left" valign="middle">Programme Name: <?php echo $qr_fetch_sem_result_ans['programme_name'];?></td>
</tr>
<tr>
<td colspan="11" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="27%">Seat No.: <?php echo $qr_fetch_sem_result_ans['seatNo'];?></td>
<td width="3%"> </td>
<td width="22%">PR No. : <?php echo $qr_fetch_sem_result_ans['prn'];?></td>
<td width="2%"> </td>
<td width="17%">Semester : <?php echo $qr_fetch_sem_result_ans['semisterName'];?></td>
<td width="1%"> </td>
<td width="25%">Month / Year Of Exam : <?php echo $qr_fetch_sem_result_ans['month_year_of_exam'];?> </td>
<td width="3%"> </td>
</tr>
<tr>
<td colspan="3">Name: <?php echo $qr_fetch_sem_result_ans['student_name'];?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="7">College / Institute: <?php echo $qr_fetch_sem_result_ans['institute_name'];?></td>
<td> </td>
</tr>
</table></td>
</tr>

I'm going to go out on a limb here and suggest that you run your queries fist and then build your pdf file. If you run the queries after you build the pdf then of course it will not have access to your data. If that doesn't help then I must not understand what you're asking.

Related

retrieve data from confused html mail using php

I need to retrieve confused html from a mail. so I have done it before using the class but here is different...so I need the part in the table---td-div with the details about the module subsciber. but before this table you have others. here is the html:
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>Nome: GIANCARLO</div>
</td>
</tr>
<tr>
<td>
<div>Cognome: CANNONE</div>
</td>
</tr>
<tr>
<td>
<div>Codice Fiscale: CNNGCR65T01A285W</div>
</td>
</tr>
<tr>
<td>
<div>Email: giancarlocannone#hotmail.com</div>
</td>
</tr>
</tbody>
</table>

PHP/HTML: Replace everything between <TD colspan=6 ...> .... </TD>

I want to replace everything between a TD-Tag that has the attribute/value colspan=6.
All this I want to replace ...
<TD colspan=6 rowspan=4 align="center" nowrap="1">
<TABLE>
<TR>
<TD width="50%" nowrap=1><font size="3" face="Arial">
Some Text
</font>
</TD>
</TR>
<TR>
<TD width="50%" nowrap=1><font size="3" face="Arial">
Some Text
</font>
</TD>
</TR>
<TR>
<TD width="50%" nowrap=1><font size="3" face="Arial">
Some Text
</font>
</TD>
</TR>
</TABLE>
</TD>
...with this lines:
<TD colspan=12 rowspan=2 align="center" nowrap="1">
<TABLE>
<TR>
<TD>frei</TD>
Some Text
</TR>
</TABLE>
</TD>
Any Ideas? Maybe with simple_html_dom.php?
Solved with PHP and Regex:
$plan1 = preg_replace('~<TD colspan=6.*?</TR></TABLE></TD>~s",
"<TD colspan=12 rowspan=2 align="center" nowrap="1">
<TABLE><TR><TD></TD></TR></TABLE></TD>', $plan1);

How to automatically generate rowspan using php

In this code everything is perfect except that I could not generate rowspan in the Internal Grade cell. this line <td rowspan="<?php echo $cols;?>"> hides the bottom border while I expect to span the rows every time the code generates rows. Thanks for your input and sorry for using mysql() function. I am newbie.
<?php $cols=mysql_num_rows($grds); ?>
<table>
<?php do{ ?>
<tr>
<td> </td>
//This hide the bottom border
<td rowspan="<?php echo $cols;?>">Internal<br />Grades</td>
<td colspan="2"> <?php echo strtoupper($row_grds['grade_name']); ?></td>
<td><?php echo strtoupper($row_grds['igrade']); ?></td>
<?php } while ($row_grds=mysql_fetch_assoc($grds)); ?>
</tr>
</table>
The output is like below:
output is here
The code generated by php is:
<table>
<tr>
<td> </td>
<td rowspan="1"> </td>// A
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td rowspan="2"> </td>//B
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
</table>
I want to merge A and B
Expected output is:
<table>
<tr>
<td> </td>
<td rowspan="2"> Internal<br /> Grade</td>
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
</table>
You can do something similar to this:
<table>
<?php $row_grds = mysql_fetch_assoc($grds); ?>
<tr>
<td> </td>
<td rowspan="<?=$cols;?>">Internal<br />Grades</td>
<td colspan="2"> <?=strtoupper($row_grds['grade_name']);?></td>
<td><?=strtoupper($row_grds['igrade']);?></td>
</tr>
<?php while ($row_grds=mysql_fetch_assoc($grds)): ?>
<tr>
<td> </td>
<td colspan="2"> <?=strtoupper($row_grds['grade_name']);?></td>
<td><?=strtoupper($row_grds['igrade']);?></td>
</tr>
<?php endwhile; ?>
Its not perfect but you are using mysql_fetch_assoc, which on its own is not perfect either :D

store part of the page in variable

i have a page contains a table and this table contains a lot of coding like this
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
<? $res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){ ?>
<tr style="width:700px">
<td class="tabletext"><?= ++$serial;?></td>
<td class="tabletext" ><?= $resArr[stName];?></td>
<td class="tabletext"><?= $resArr['date'];?></td>
<td class="tabletext" ><?= $resArr[matName];?></td>
<td class="tabletext" ><? if($resArr[exam]==1) echo "work";else echo "final";?></td>
<td class="tabletext" ><? if($resArr[exam_type]==1) echo "prac";else echo "test";?></td>
</tr>
<? }?>
</tbody>
</table>
as you see the table has php coding
now i want to store the whole table in variable so i can send it to pdf printing library tcpdf
You can use heredoc syntax, but you need to move the conditionals outside:
<?php
if($resArr['exam']==1) $exam = "work"; else $exam = "final";
if($resArr["exam_type"]==1) $examtype = "prac";else $examtype = "test";
$var = <<<EOT
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
$res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){
<tr style="width:700px">
<td class="tabletext">{++$serial}</td>
<td class="tabletext" >{$resArr["stName"]}</td>
<td class="tabletext">{$resArr["date"]}</td>
<td class="tabletext" >{$resArr["matName"]}</td>
<td class="tabletext" >{$exam}</td>
<td class="tabletext" >{$examtype}</td>
</tr>
<? }?>
</tbody>
</table>
EOT;
echo $var;
Another way, if you already have all of this code and want to save it:
Before the table:
<?php ob_start(); ?>
After the table:
<?php $output = ob_get_contents(); ?>
The table will still be displayed and you can use $output to send to the PDF.

update mysql table with list values

i have a form that extract data from mysql table into a form, each row has a menu to choose a value from and i want to update mysql with each value choosen for each row when the 'Apply To All' button is clicked but doesnt work at all.,here is my code.
<td><form id="main" name="main" method="post" action="setProjectStatus.php" onsubmit="return validateMain();">
<table width="100%" cellspacing="1" cellpadding="1">
<tr>
<td width="35%" rowspan="3"><img src="../img/project.jpg" alt="Comp Sci Stud" width="325" height="199" border="2" /></td>
<td width="65%" height="42" colspan="2"><table width="94%" cellpadding="1" cellspacing="1" class="main_table">
<tr class="table_title">
<td width="100%" class="table_title">Set Project Status. </td>
</tr>
<tr>
<td height="26"> </td>
</tr>
<tr>
<td height="26"><table width="100%" cellspacing="1" cellpadding="1">
<tr class="table_head">
<td width="2%" height="35"><div align="center"></div></td>
<td width="26%" height="35"><div align="center">Student Name</div></td>
<td colspan="2"><div align="center">Project</div></td>
<td width="19%"><div align="center">Status</div></td>
</tr>
<?php
session_start();
$username = $_SESSION['username'];
require_once("mysqlConnect.php");
//
$sql="SELECT * FROM spms_Student";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
echo "There are $count projects to be undertaken.";
while($rows=mysql_fetch_array($result)){
//
$query = "SELECT name FROM spms_systemUser WHERE userId = '".$rows[0]."'";
$result1 = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result1);
$name = $row[0];
?>
<tr>
<td height="25" align="center"> </td>
<td align="center"><?php echo $name; ?></td>
<td colspan="2" align="center"><?php echo $rows[1]; ?></td>
<td align="center"><label>
<select name="select" class="form_field_100px_select">
<option value="Pending" selected="selected">Pending</option>
<option value="Approved">Approved</option>
<option value="Disapproved">Disapproved</option>
</select>
</label></td>
</tr>
<?php
}
?>
<tr class="pager_bg">
<td height="35"> </td>
<td> </td>
<td width="37%" align="right"><input name="done" type="button" id="done" value="Done" onclick="window.location='../coordinatorMenu.html'" /></td>
<td width="16%"><label>
<input name="approveAll" type="submit" id="approveAll" value="Approve All" />
</label></td>
<td><input name="apply" type="submit" id="apply" value="Apply To All" /></td>
</tr>
<?php
mysql_close();
?>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><label></label> <label></label></td>
</tr>
</table>
</form></td>
You're trying to reuse your MySQL connection while still holding on to the resultset from the first query. You need to create a second connection for the inner loop queries. Even better would probably be to rewrite your query using a join, but I can't say for sure without knowing your schema.

Categories