Click here to Skip to main content
15,913,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
I want to fetch records and pdf files from mysql using php.. with a option delete records and while displaying from table all other records will be displayed except pdf files. for pdf file I want a link as "show pdf" or "read more". if clicked on this link, pdf file of that particular record should open up in new window. For this i tried using

XML
<form name="form2" action="test_mix.php" method="POST">

<table id="displaytable" width="400" border="0" align="center" cellpadding="0" cellspacing="1" style="vertical-align:middle;">
<tr>
<td><table width="421" height="279" border="0" cellpadding="3" cellspacing="1">
<tr>
<td width="29" rowspan="5" style="vertical-align:middle;">
<?php

echo "<input type=checkbox name=del[] id=del value=$rows[id]>";
?>


</td>
</tr>

<tr>
<td width="83">Date</td>
<td width="6">:</td>
<td width="276"><?php echo $rows['date']; ?></td>
</tr>

<tr>
<td valign="top">Title</td>
<td valign="top">:</td>
<td><?php echo $rows['title']; ?></td>
</tr>
<tr>

<tr>
<td valign="top">News</td>
<td valign="top">:</td>
<td><?php echo $rows['news']; ?></td>
</tr>
<tr>
<td height="55" valign="top" style="vertical-align:middle;"></td>
<td valign="top"><?php echo "<input type=checkbox id=pdf value=$rows[id] onclick=Button1() name=pdf[];/>" ?>
<!--<input type="submit" name=pdf[] id=pdf value=$rows[id] formtarget="_blank" src="Untitled-7.php" />
-->
<!--<a href="javascript:void(0);"<?php /*?> <?php name=pdf[]; id=pdf; value=$row[id];?><?php */?> onclick="javascipt:window.open('Untitled-7.php');" class="popup">Clic to open.</a>-->

<!--<a href="Untitled-7.php" target="_blank" >Read More</a>--></td>
<td height="200" width="6" style="overflow:auto;">:</td>

<?php /*?><?php echo $rows['file']; ?><?php */?>
</tr>


</table></td>
</tr>
</table>

<?php
}
mysql_close(); //close database
?>
<!--<input type="submit" name="justdel" value="Delete !!" id="justdel" style="float:right;">-->
<INPUT type="button" value="Delete !!" name=justdel  id="justdel" onclick="return OnButton2();"  style="float:right;">
</form>



and this is test_mix.php

PHP
<?php
 //delete.php
include('update_config.inc');

if($_POST['del']=""){

//if(isset($_POST['justdel'])){

//if(($_POST['del']) = "";){

$id = $_POST['del'];
$count = count($id); //counting how many rows (from checkbox) to delete
for ($i=0; $i<$count; $i++)
{
$sql = mysql_query("delete from $tbl_name where id=$id[$i]") or die(mysql_error());
}
if ($sql)
{
header("location:adminupdates.php");
}
}
else if(($_POST['pdf']="")){

$id = $_POST['pdf'];
$count = count($id); //counting how many rows (from checkbox) to delete
//if($_POST['pdf'])

$gotten = @mysql_query("select file from $tbl_name where id=$count limit 1");
$row = @mysql_fetch_assoc($gotten);
$bytes = $row['file'] or die(mysql_error());
//header("Content-Description: PHP Generated Data");
header("Content-transfer-encoding: binary");
header("Content-type: application/pdf");
//header('Content-disposition: attachment; filename="thing.pdf"');
//print $bytes;

 print $bytes;

        }
    else{echo "in three";}
//}
?>


can any one please help me in this..
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900