how to put a tooltip in a looping calendar - php

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.

Related

Simplifying PHP for further use

I am totally new to PHP and mySQL. I have pulled this data from mySQL database for a wordpress website but I would like to simplify my code so that it's more flexible so that I could customize my tables more easily. Any suggestion on where to start and also is there a standard way to do this ?
<?php
global $wpdb;
$result1 = $wpdb->get_results("SELECT ID, post_title, post_date, guid, post_type FROM wp_posts");
$result2 = $wpdb->get_results("SELECT name, term_id FROM wp_terms");
$result3 = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM wp_term_relationships");
echo "<style>";
echo "body {font-family: Arial;}";
echo ".table_container { padding: 10px 12px 0px 12px; border: 1px solid #ccc; }";
echo ".table_container th { background-color:white; color:black; font-weight:bold; border-left: 1px solid white;}";
echo "</style></head>";
echo "<body>";
echo "<div class=\"table_container\"><table>";
echo "<tr><th style=\"padding-left:10px;\">Yvirskrift</th><th>Dato</th><th>Talari</th><th>Lurta</th></tr>";
foreach ($result1 as $row1) {
if ($row1->post_type == "podcast") {
echo "<tr>";
echo "<td> $row1->post_title </td>";
$date = date("d-m-Y", strtotime($row1->post_date));
echo "<td> $date </td>";
foreach ($result3 as $row3) {
if ($row1->ID == $row3->object_id) {
foreach ($result2 as $row2) {
if($row3->term_taxonomy_id == $row2->term_id){
echo "<td> $row2->name </td>";
}
}
}
}
$listen = "<a href=$row1->guid>Lurta her</a>";
echo "<td> $listen </td>";
echo "</tr>";
}
}
echo "</table></div>";
?>

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>

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!

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

Categories