Limit Character in a table - php

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>";
}

Related

Creating a Responsive Table With Data from phpmysql

The below table prints data form a mysql db. Is it possible to make it responsive to adapt to even the smallest devices without losing the image. I am studying bootstrap to see how it can work.
<style>
body { margin: 0; font-family: Arial, Helvetica, sans-serif; }
.content { margin: auto; width: 99.8%; height:79.8%; border: 1px solid green; padding: 10px; background-color: magenta; }
</style>
<div class="content">
<div class="row">
<div class="col">
<?php
print "<table border=1 width=100%>";
print "<td width=10px height=auto bgcolor=#00FF33>" . $row['id'] . "</td>";
print "<td width=200px height=200px>"."<a href='".$row['image']."'><img src=".$row['image']."width=100% height=100%</a>" ."</td>";
print "<td>";
print "<table border=1 width=100%>";
print "<tr>";
print "<td>" . $row['imagename'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['name'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['username'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['useremail'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>" . $row['userphone'] . "</td>";
print "</tr>";
print "<tr>";
print "<td>"."<a href='id=$uniqueid' >More Details</a>"."</td>";
print "</tr>";
print "<tr>";
print "<td>"."<a href='id=$uniqueid' >Contact Seller</a>"."</td>";
print "</tr>";
print "</table>";
print "</td>";
print "</table>";
print "<br />";
?>
</div>
Incase you're using bootstrap just add "table table-responsive" to your table class
<table class="table table-responsive">

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()

Search into database based on user input [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
I am a newbie in PHP. I am working on searching function, but it does not work well and I could not find why. The problem is; the $query has been sent and accepted well however it could not find the $query in the database even though the $query existed. I think, the $sql command might be wrong somewhere, but could not find it anyway. Thank you.
Here is my code: asset_search.php
<?php
//Search data in database
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length)
{
//$query = htmlspecialchars($query);
//$query = mysql_real_escape_string($query);
$query = strtoupper($query);
$sql = "SELECT * FROM asset WHERE ('asset_name' LIKE '%".$query."%')";
$result = mysqli_query($conn, $sql);
$row_cnt = mysqli_num_rows($result);
$count = 0;
if($row_cnt > 0)
{
echo "<table style='padding: 5px; font-size: 15px;'>";
echo "<tr><th style='width: 30px; border: 1px solid black; align:'center''>No</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Status</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Asset Sub-identifier</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Asset Name</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Asset Type</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Brand</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Service Tag/ Product Tag/ Product S/N</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>CSM Tag</th>";
echo "<th style='width: 200px; border: 1px solid black; align:'center''>Action</th></tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr><td align='center'>" . ++$count . "</td>";
echo "<td align='center'>" . $row["asset_status"] . "</td>";
echo "<td align='center'><a href='asset_viewfull.php?asset_id=" . $row["asset_id"] . "'><ins>" . $row["asset_subidentifier"] . "</a></ins></td>";
echo "<td align='center'>" . $row["asset_name"] . "</td>";
echo "<td align='center'>" . $row["asset_type"] . "</td>";
echo "<td align='center'>" . $row["asset_brand"] . "</td>";
echo "<td align='center'>" . $row["asset_sertag"] . "</td>";
echo "<td align='center'>" . $row["asset_csmtag"] . "</td>";
if($row["asset_status"] == "DISPOSE")
{
echo "<td align='center'><a href='asset_delete.php?asset_id=" . $row["asset_id"] . "'>Delete</a>";
echo " ";
echo "<a href='asset_print.php?asset_id=" . $row["asset_id"] . "'>Print</a></td></tr>";
}else
{
echo "<td align='center'><a href='asset_editform.php?asset_id=" . $row["asset_id"] . "'>Edit</a>";
echo " ";
echo "<a href='asset_delete.php?asset_id=" . $row["asset_id"] . "'>Delete</a>";
echo " ";
echo "<a href='asset_disposeform.php?asset_id=" . $row["asset_id"] . "'>Dispose</a>";
echo " ";
echo "<a href='asset_print.php?asset_id=" . $row["asset_id"] . "'>Print</a></td></tr>";
}
}
}else
{
echo "<tr> There is no asset in the database </tr>";
}
echo "</table>";
}
else
{
echo "<script languange = 'Javascript'>
alert('Minimum length is' .$min_length);</script>";
}
//Close connection
mysqli_close($conn);
$count = 0;
?>
Change your query to the following:
SELECT * FROM asset WHERE (`asset_name` LIKE '%".$query."%')
Note the `` around asset_name instead of ''
you should try this without the brackets sometimes it trows out the search,
$sql = "SELECT * FROM asset WHERE `asset_name` LIKE '%{$query}%'";
this is how i preform this task and has never failed me yet!

PHP + Shell Returning HTML

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');
?>

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