PHP + Shell Returning HTML - php

I am currently having an issue where I am trying to execute a shell script which interprets a file and echos back html, the shell script executes perfectly locally however when I try to execute through php it doesn't return anything, and seems are though php isn't executing it at all, I have a file which is created when the script is executed which doesn't show up with php execution. I have other scripts which are executed with php and work completely fine, and I have proper www-data permissions to execute this file. Please help me, here is the script I am trying to execute and the php file which is executing it.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th style="font-size: 24px" scope="col"><p align="left" class="title_Font">Magnum Dongs <span style="font-size: 18px"> | Mighty Meat Sticks 4 Kidz</span></p></th>
</tr>
</tbody>
</table>
<ul align="center" width="1000" height="50">
<li>Home</li>
<li>Stories</li>
<li>Memes</li>
<li>Shop</li>
<li>Email</li>
</ul>
<table width="1000" height="386" border="0" align="center" cellpadding="0" cellspacing="0" class="body_Main">
<tbody>
<?php
echo exec('./var/www/html/newdongs/fetch_html.sh');
?>
</tbody>
</table>
</body>
</html>
#!/usr/bin/env bash
python3 /bin/dongs/db_Read.py >> lines
#1
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==11' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==41' lines`"</p>"
echo "<img src='"`awk 'NR==31' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==21' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#2
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==12' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==42' lines`"</p>"
echo "<img src='"`awk 'NR==32' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==22' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#3
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==13' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==43' lines`"</p>"
echo "<img src='"`awk 'NR==33' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==23' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#4
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==14' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==44' lines`"</p>"
echo "<img src='"`awk 'NR==34' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==24' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#5
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==15' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==45' lines`"</p>"
echo "<img src='"`awk 'NR==35' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==25' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#6
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==16' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==46' lines`"</p>"
echo "<img src='"`awk 'NR==36' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==26' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#7
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==17' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==47' lines`"</p>"
echo "<img src='"`awk 'NR==37' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==27' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#8
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==18' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==48' lines`"</p>"
echo "<img src='"`awk 'NR==38' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==28' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#9
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==19' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==49' lines`"</p>"
echo "<img src='"`awk 'NR==39' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==29' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
#10
echo "<tr>"
echo "<th scope='col'>"
echo "table width='1000' border='0' class='post' align='center' style='margin-top: 10px;'>"
echo "<tbody>"
echo "<tr>"
echo "<th scope='col' width='50'>"
echo "<p style='font-size: 0px; margin:0px; ' align='center'> Posted By: "`awk 'NR==20' lines`"</p>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Total Score: "`awk 'NR==50' lines`"</p>"
echo "<img src='"`awk 'NR==40' lines`"' width='150' height='150' alt=''/>"
echo "<p style='font-size: 0px; margin: 0px; ' align='center'> Upvote | Downvote</p>"
echo "</th>"
echo "<th scope='col' align='left' valign='top'>"
echo "<p class='post' style='font-size: 14px'>"`awk 'NR==30' lines`"</p>"
echo "</tr>"
echo "</tbody>"
echo "</table></th>"
Thanks for the help in advance!

I think the issue is with PHP looking for the script in the wrong location.
You can get the current working directory using getcwd(). Check if you are using the correct relative path to the script from your current working directory.
Else you could simply pass the absolute path to the script to the exec() command.
The next problem is your shell script prints quite a few lines and ends with the tags </table></th>. The exec() function returns only the last line of the shell script output. So the PHP output will show only the </table></th>. This cannot be rendered in HTML as they are only the closing tags. Hence you see no change in the browser but you can notice it if you inspect the HTML.
Instead you can use shell_exec() to return the entire output of the shell script.
Here is the corrected version:
<?php
// 1.Remove the leading dot. The leading dot makes the path relative.
// 2.Use shell_exec instead to get all lines from your script output.
echo shell_exec('/var/www/html/newdongs/fetch_html.sh');
?>

Related

Pagination trouble with php and postgresql

I am trying to do a simple pagination exercise with HTML table but only page 2 shows info. It doesn't show table information when I hit 'previous' button.
For example, when I open the page, it shows nothing. When I click on page 2, there is information. When I reach the end, all is ok but then I click 'previous' button or page 1 and it does not show anything again.
$rowperpage = 5; // Total rows display
$row = 0;
if(isset($_GET['page'])){
$row = $_GET['page']-1;
if($row < 0){
$row = 0;
}
}
$link = pg_connect("host=127.0.0.1 port=5432 dbname=swxxxg5_en user=swapng5_control password=xxxxxxxx");
$query = "select id from registrados";
$resultfichados = pg_query($link, $query);
$totalfichados = pg_num_rows($resultfichados);
$allcount = pg_num_rows($resultfichados);
//echo $allcount;
$limitrow = $row*$rowperpage;
$db = pg_connect("host=127.0.0.1 port=5432 dbname=swxxxg5_en user=swapng5_control password=xxxxxxxxxxxxx");
$result = pg_query($db,"select
id,
usuario,
nombre,
apellido,
flag,
reputacion,
ingreso,
lastlogin,
passport,
loyalty,
certified
from registrados order by id asc limit " . $limitrow . " offset 0");
//from registrados order by reputacion asc limit 5 offset 0");
?>
<table align='center' class='table table-hover table-striped' id='t01'>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>id</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Usuario</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Nombre</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Apellido</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Flag</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Reputacion</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Ingreso</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Lastlogin</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Passport</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Loyalty</td>
<td align='center' style='font-weight:bold; color:#fff; background: #3498db;'>Certified</td>
<?php
while($rowdatauser=pg_fetch_assoc($result)){
echo "<tr>";
echo "<td align='center' width='200' style='color:#7f8c8d; font-weight:bold;'>" . $rowdatauser['id'] . "</td>";
echo "<td align='center' width='200' style='color:#7f8c8d; font-weight:bold;'>" . $rowdatauser['usuario'] . "</td>";
echo "<td align='center' width='200'>" . $rowdatauser['nombre'] . "</td>";
echo "<td align='center' width='60'>" . $rowdatauser['apellido'] . "</td>";
echo "<td align='center' width='60' style='background: #e74c3c; color:#fff; font-weight:bold;'>" . $rowdatauser['flag'] . "</td>";
echo "<td align='center' width='200' style='background: #ff9900; font-weight:bold;'>" . $rowdatauser['reputacion'] . "</td>";
echo "<td align='center' width='200'>" . $rowdatauser['ingreso'] . "</td>";
echo "<td align='center' width='200' style='background: #58c0ce;'>" . $rowdatauser['lastlogin'] . "</td>";
echo "<td align='center' width='200'>" . $rowdatauser['passport'] . "</td>";
echo "<td align='center' width='200'style='background: #7863a0; color:white; font-weight:bold;'>" . $rowdatauser['loyalty'] . "</td>";
echo "<td align='center' width='200'>" . $rowdatauser['certified'] . "</td>";
echo "</tr>";
}
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #fff;'></td>";
echo " <td align='center' style='background: #4567;'>TOTALES</td>";
echo "<td align='center' width='200' style='background: #eee;'>", $totalfichados ,"</td>";
echo "</table>";
?>
<!-- Number list (start) -->
<ul class="pagination">
<?php
// calculate total pages
$total_pages = ceil($allcount / $rowperpage);
$i = 1;$prev = 0;
// Total number list show
$numpages = 5;
// Set previous page number and start page
if(isset($_GET['next'])){
$i = $_GET['next']+1;
$prev = $_GET['next'] - ($numpages);
}
if($prev <= 0) $prev = 1;
if($i == 0) $i=1;
// Previous button next page number
$prevnext = 0;
if(isset($_GET['next'])){
$prevnext = ($_GET['next'])-($numpages+1);
if($prevnext < 0){
$prevnext = 0;
}
}
// Previous Button
echo '<li >Previous</li>';
if($i != 1){
echo '<li ><a href="?page='.($i-1).'&next='.$_GET['next'].'" ';
if( ($i-1) == $_GET['page'] ){
echo ' class="active" ';
}
echo ' >'.($i-1).'</a></li>';
}
// Number List
for ($shownum = 0; $i<=$total_pages; $i++,$shownum++) {
if($i%($numpages+1) == 0){
break;
}
if(isset($_GET['next'])){
echo "<li><a href='?page=".$i."&next=".$_GET['next']."'";
}else{
echo "<li><a href='?page=".$i."'";
}
// Active
if(isset($_GET['page'])){
if ($i==$_GET['page'])
echo " class='active'";
}
echo ">".$i."</a></li> ";
}
// Set next button
$next = $i+$rowperpage;
if(($next*$rowperpage) > $allcount){
$next = ($next-$rowperpage)*$rowperpage;
}
// Next Button
if( ($next-$rowperpage) < $allcount ){
if($shownum == ($numpages)){
echo '<li >Next</li>';
}
}
?>
</ul>
<!-- Numbered List (end) -->
I guess you are trying to paginaate using LIMIT a OFFSET b system. In that case, your a should be the page size and b the place where you start.
This system has it's limitations, like when rows are added or removed the same time you are viewing data, but if this is acceptable, then it might be the easiest way.
Other ways to paginate are shown in this article.
Two notes: One DB handle is enough, you don't need two connections. And if you want to count the rows in yous set, SELECT count(*) FROM... is easier than pg_num_rows()

Hide DIV or button based on query result

I am trying to hide a DIV or the pertaining button based on a value stored in the session (which gathers user data on login). For example, if someone logs in with the access code of 20, I want certain buttons to be disabled, hidden, etc. This is an internal portal with beginner users using it, so I'm thinking simple. Any other ideas are more than welcome. How can I do this?
Here is my current code. I've removed the style attributes for the post. Thanks all.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>MK Diamond - Main Menu</title>
<style type="text/css">
</style>
</head>
<?php
include("session.php");
echo "<body style=\"background-attachment: fixed; background-image: url('img/background.jpg');\">";
echo "<div class=\"auto-style1\" style=\"height: 213px; width: 100%; float: left;\">";
echo "<span class=\"auto-style5\">";
echo "<span class=\"auto-style22\"><strong>This portal is for MK Diamond use ";
echo "only. Any and all access is monitored and controlled - unauthorized ";
echo "attempts will be investigated.</strong></span><br>";
echo "<img src=\"img/mk-logo.png\" height=\"185\" width=\"375\"/></span><br>";
echo "</div>";
echo "<div>";
echo "<table style=\"width: 65%\" align=\"center\" class=\"auto-style7\">";
echo "<tr>";
echo "<td class=\"auto-style21\" style=\"height: 24px\"></td>";
echo "<td class=\"auto-style21\" style=\"height: 24px; width: 25px;\"> </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style18\" style=\"height: 24px\">";
echo "<input name=\"jobsbutton\" type=\"button\" value=\"M.S. Jobs Menu\" onclick=\"location.href='jobsmenu.php'\" style=\"width:160px; height: 35px\" /></td>";
echo "<td class=\"auto-style18\" style=\"height: 24px; width: 25px;\"> </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "<input name=\"ordersbutton\" ID=\"ordersbutton\" type=\"button\" value=\"B.V. Orders Menu\" onclick=\"location.href='ordersmenu.php'\" style=\"width: 160px; height: 35px\" />";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo " </td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "You are logged in as "; echo "$row[name]";
echo "</span> Logout</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style23\" style=\"height: 24px\">";
echo "Security Class: "; echo "$row[acctype]";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "<strong>Welcome to the Main Menu</strong></td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"auto-style19\" style=\"height: 24px\">";
echo "<input name=\"Button1\" type=\"button\" value=\"Release Notes\" onclick=\"location.href='releasenotes.php'\" style=\"width: 160px; height: 35px\" />";
echo "</td>";
echo "<td class=\"auto-style19\" style=\"height: 24px; width: 25px;\">";
echo " </td></tr>";
echo "</table>";
?>
</div>
<div class="auto-style8">
</div>
</body>
</html>

Limit Character in a table

Thanks to stackoverflow and its great solution, I have found a way to limit the characters in a table but it doesn't work for me. I tried a lot but with no success.
This is my table
<?php
$result = mysqli_query($conn,"SELECT * FROM library ORDER BY `CreatedTime` DESC");
echo "<table class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Book Name</th>
<th width='5%'></th>
</tr>";
while($row = mysqli_fetch_array($result) ) {
echo "<tr>";
echo "<td colspan='2' style='padding-bottom: 0;'><a href='library.details.php?id=". $row['id']."' target='content' class='positiontitle-link'><font style='text-shadow: none; font-weight: 800;'>" . $row['bookname']. "</td>";
echo "</tr>";
echo "<tr style='border-top-width: 0; padding-top: 0;'>";
echo '<td style="max-height: 10px;">' . $str . '</td>';
echo "<td style=' padding-top: 0; padding-left: 15px; width: 40%;'> <font color='gray'>Author :</font> " .($row['authorname'] ). "</td>";
echo "<td width='5%' style=' padding-top: 0;'> <font color='gray'>Year Published </font>" . $row['yearpublished'] . "</td>";
echo "</tr>";
if (strlen($row['bookname']) > 1) $str = substr($row['bookname'], 0, 1) . "...";
}
echo"</table>";
?>
This is how it looks like
Any help will be appreciated.
I'm doing this out of my head so forgive me any format issues and such...
Move the string length check to just under the while.
Overwrite $row['bookname'] instead of creating $str.
Remove the line with:
echo '<td style="max-height: 10px;">' . $str . '</td>';
Result:
while($row = mysqli_fetch_array($result) ) {
if (strlen($row['bookname']) > 9) $row['bookname'] = substr($row['bookname'], 0, 9) . "...";
echo "<tr>";
echo "<td colspan='2' style='padding-bottom: 0;'><a href='library.details.php?id=". $row['id']."' target='content' class='positiontitle-link'><font style='text-shadow: none; font-weight: 800;'>" . $row['bookname']. "</td>";
echo "</tr>";
echo "<tr style='border-top-width: 0; padding-top: 0;'>";
echo "<td style=' padding-top: 0; padding-left: 15px; width: 40%;'> <font color='gray'>Author :</font> " .($row['authorname'] ). "</td>";
echo "<td width='5%' style=' padding-top: 0;'> <font color='gray'>Year Published </font>" . $row['yearpublished'] . "</td>";
echo "</tr>";
}

convert Div tag of my page into pdf in php while data is coming from databse

I want to convert the valve which are inside of the DIV tag to PDF file
<div id="container2">
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db('account',$con);
$query1="Select * from e_bills";
$result=mysql_query($query1);
echo "<table width='1000' border='5' cellpadding='2' id='bill'>
<tr>
<th style='border:1px solid black'><input type='checkbox'></th>
<th style='border:1px solid black'>BillNo</th>
<th style='border:1px solid black'>Amount</th>
<th style='border:1px solid black'>VendorName</th>
<th style='border:1px solid black'>Date</th>
<th style='border:1px solid black'>Paid</th>
<th style='border:1px solid black'>Pending</th>
<th style='border:1px solid black'>Action</th</tr>";
//$res=mysql_fetch_array($result);
//print_r($res);
while($res=mysql_fetch_array($result))
{
$pending=$res['bi_total']-$res['bi_paid'];
echo "<tr> <td style='border:1px solid black';>";
echo "<input type='checkbox' class='ads_Checkbox' id='checkbox.$res[bi_billnumber]' value='$res[bi_billnumber]'>";
echo " </td>";
echo "<td style='border:1px solid black';>";
echo "B_".$res['bi_billnumber'];
echo "</td>";
echo "<td style='border:1px solid black';>";
echo $res['bi_total'];
echo "</td> ";
echo "<td style='border:1px solid black';><a style='color:red;text-decoration:underline;cursor:pointer;'onclick='getdata1($res[bi_billnumber])'>";
echo $res['bi_vendername'];
echo "</a></td>";
echo "<td style='border:1px solid black';>";
echo $res['bi_date'];
echo "</td>";
echo "<td style='border:1px solid black';>";
echo $res['bi_paid'];
echo "</td>";
echo "<td style='border:1px solid black';>";
echo "$pending";
echo "</td>";
echo "<td style='border:1px solid black';>";
echo "<input type='button' name='button' value='Edit' onclick='getdata($res[bi_billnumber])'>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
</form>
</div>
I have Used
<?php
include("/MPDF53/MPDF53/mpdf.php");
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML(file_get_contents('billdisplay.php'));
$mpdf->Output();
?>
But useful for only from static values not for the data which is coming from the database.
You can use the dompdf for converting your html to pdf. It is so simple and it also take php code . Dompdf Example

how to put a tooltip in a looping calendar

how can i put a tooltip in a specific date? Can someone please help me. I really need this
and how can i put a ajax so that my calendar doesn't refresh
This is my code.
<?php
error_reporting(0);
Class CALEVENTS
{
var $host;
var $user;
var $password;
var $database;
var $db=NULL;
function CALEVENTS($host="",$user="",$password="",$database="")
{
$this->setInfo($host,$user,$password,$database);
}
function setInfo($host,$user,$password,$database)
{
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
//$this->db=new DB();
//$this->db->open($this->host,$this->user,$this->password,$this->database);
$this->db=mysql_connect($this->host,$this->user,$this->password);
mysql_select_db($this->database);
}
function drawCalendar()
{
$db_event=$this->db;
if(isset($_GET['time']))
$time=$_GET['time'];
else
$time=time();
$today = getdate($time);
$mday = $today ['mday'];
$mon = $today ['mon'];
$year = $today ['year'];
$time = mktime(0, 0, 0, $mon,1,$year);
$today = getdate($time);
$wday = $today ['wday'];
$year = $today ['year'];
$weekday = $today ['weekday'];
$month = $today ['month'];
$i= -$wday;
$thisPage=$_SERVER['PHP_SELF'];
$time = mktime(0, 0, 0, $mon+1,0,$year);
$lastDay=date('j',$time);
$sql="SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle,eventID FROM events WHERE eventDate BETWEEN '$year/$mon/01' AND '$year/$mon/31'";
//$db_event->query($sql);
$result=mysql_query($sql,$db_event);
$events=array();
//while($row_event=$db_event->fetchObject())
// $events[intval($row_event->day)].=$row_event->eventContent."<br><br>";
while($row_event=mysql_fetch_object($result))
$events[intval($row_event->day)].=$row_event->eventTitle."<br>" .$row_event->eventContent;
echo "<style>\n";
echo ".event_cls {background-color: #b7c8ef; color:white; font-weight: bold; text-decoration: none; cursor: hand;}\n";
echo " <div id='event' style=' left: 395px; top: 192px; color:black'></div></td> </tr> </table>\n";
echo ".event_cls:hover {background-color:ced9f0;}";
echo ".event_col:hover {background-color:ced9f0;}";
echo ".event_head{background-color: #333b73; color:white; font-weight:bold;FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 12px;}\n";
echo ".event_col{background-color:#e2e6ef; color:#000095; FONT-FAMILY: Verdana, Geneva, Arial, Helvetica, sans-serif;FONT-SIZE: 11px; height='75' width='75'}\n";
echo ".event_link {TEXT-DECORATION: none; color:#0DB0FF;}\n";
echo "</style>";
echo "<table width='870' border='0' align='center' style='border-style:solid;border-width:1px;position:relative;top:15px;left:15px;' cellspacing='1'>\n";
echo "<tr class='event_col' align='center'> \n";
echo "<td height='75'><b><a href='$thisPage?time=".mktime(0, 0, 0, $mon-1,$mday,$year)."' title='Previous Month' class='event_link'><</a></b></td>\n";
echo "<td colspan='5' class='event_col'> <b>$month $year</b></td>\n";
echo "<td height='75'><b><a href='$thisPage?time=".mktime(0, 0, 0, $mon+1,$mday,$year)."' title='Next Month' class='event_link'>></a></b></td>\n";
echo "</tr>\n";
echo "<tr class='event_col' height='25''>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Sunday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Monday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Tuesday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Wednesday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Thursday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Friday</td>\n";
echo "<td align='center' height='75' width='75' class='event_head'>Saturday</td>\n";
echo "</tr>\n";
echo "<script>\n";
foreach($events as $key => $value)
echo "evnt$key=\"$value\"\n";
echo "function showevent(day)\n";
echo "{";
echo " evnt=eval('evnt'+day);\n";
echo " mydiv=document.getElementById('event');\n";
echo " mydiv.innerHTML=evnt\n";
echo "}";
echo "</script>\n";
for($j=0;$j<6;$j++){
echo "<tr> \n";
for($k=0;$k<7;$k++){
$i++;
$cls="class='event_col'";
if(array_key_exists($i,$events))
$cls="class=event_cls onmouseover='showevent($i)'";
echo "<td height='75' $cls>\n";
echo ($i>0&&$i<=$lastDay)?$i:'';
echo "</td>";
}
echo "</tr>" ; }
echo " <tr > <td colspan=8 >\n";
echo " </td> </tr> </table>\n";
echo"<br/><div id='event' style=' z-index:1000; left: 395px; top: 192px; color:#000;'></div>";
}?>
I really need help.. please help me
You can set "id" to each "td" and then in javascript you can setAttribute "title" to some value.

Categories