Using JSON data in a view - php

I have a pretty complex PHP/HTML view. However, I recently changed my site to refresh automatically using AJAX. It currently returns a JSON array, and I need to reproduce my View using that data.
Here is my AJAX:
$(function() {
$( "#selectable" ).selectable({
selected: updatefilters,
});
function updatefilters(ev, ui){
// get the selected filters
var $selected = $('#selectable').children('.ui-selected');
// create a string that has each filter separated by a pipe ("|")
var filters = $selected.map(function(){return this.id;}).get().join("\|");
$.ajax({
type: "POST",
url: 'updatefilters',
dataType: 'json',
data: { filters: filters },
success: function(data){
var html = "<div id ='board'><table>";
for (i=0 ; i< data.length ; i++)
{
html += "<tr><td>" + data[i].subject + "</td><td>" + data[i].body + "</td></tr>";
}
html += "</table></div>";
$('#board').html(html);
}
});
}
});
Here is my PHP file:
<div id='board'>
<?php
if ($threads)
{
$count = count($threads);
$perpage = 17;
$startlist = 3;
$numpages = ceil($count / $perpage);
if ($page == 'home') {$page = 1;}
$threadstart = ($page * $perpage) - $perpage;
$i = 0;
echo "<table class='board'>
<tr>
<th width='5%'><img src='".base_url()."img/board/icons/category_icon.png' alt='category_icon'/></th>
<th width='5%'>Tag</th>
<th width='50%'>Subject</th>
<th width='7.5%'>Author</th>
<th width='7.5%'>Replies/Views</th>
<th width='15%'>Last Post</th>
</tr>";
foreach ($threads as $list)
{ $i++;
$thread_owner = $this->thread_model->get_owner($list['owner_id']);
$thread_id = $list['thread_id'];
$query = $this->db->query("SELECT f.tag FROM filter_thread AS ft
INNER JOIN filter AS f ON ft.filter_id = f.filter_id
WHERE thread_id = $thread_id");
$result = $query->result_array();
$trunc_body = $this->thread_model->get_reply_summary($thread_id);
$filter = "";
$filter2 ="";
$ent = "entertainment";
foreach ($result as $string)
{
if ($string['tag'] == $ent) {
$filter2 .= "<div id='entertainment'><p>";
$filter2 .= "<img src='".base_url()."img/board/icons/entertainment_icon.png' title='Entertainment' alt='Entertainment'/>";
$filter2 .= "</p></div>";
} else {
$filter2 .= "<div id='misc'><p>";
$filter2 .= "<img src='".base_url()."img/board/icons/misc_icon.png' title='Misc' alt='Misc'/>";
$filter2 .= "</p></div>";
$filter .= " [".$string['tag']."]";
}
}
if (!$result) { $filter = "" AND $filter2 =""; }
if ($i > $threadstart AND $i <= $threadstart + $perpage)
{
echo "<tr>";
echo "<td>".$filter2."</td>";
echo "<td>".$filter."</td>";
echo "<td title='".$trunc_body['0']['body']."'>".ucfirst($list['subject'])."<div id='filter'><p></p></div></td>";
echo "<td><p>".$thread_owner."</p></td>";
echo "<td align='right'>Replies: ".$list['replies_num']."<br>Views: ".$list['views']."</td>";
$owner = $this->thread_model->get_owner($list['last_post_id']);
echo "<td>".$owner." <br>".$list['replystamp'] ."</td></tr>";
}
}
echo "</table>";
echo "<br>";
echo "Current Page: $page | ";
echo "Page: ";
for ($n = 1; $n < $numpages+1; $n++)
{
echo "<a href=".base_url()."main/home/$n>$n</a> | ";
}
}
?>
</div>
is there a not too hard way of accomplishing this?

Try adding header("Content-Type: text/plain"); at the TOP of your PHP file.
Also, move the <div id='board'> to a variable inside the script - AFTER the header() function.
Furthermore, change all echo's to variables, put those variables in an array, and use
json_encode($array);
Example:
$output = "<div id='board'>";
$output .= "<table class='board'>
<tr>
<th width='5%'><img src='".base_url()."img/board/icons/category_icon.png' alt='category_icon'/></th>
<th width='5%'>Tag</th>
<th width='50%'>Subject</th>
<th width='7.5%'>Author</th>
<th width='7.5%'>Replies/Views</th>
<th width='15%'>Last Post</th>
</tr>";
echo json_encode( array('output'=>$output) );

Related

Printing a chess table in php without using for loop

How can I print a chess table in PHP without using for loops, is it possible to do it with conditional and logical statements only?
<table width = "270px" cellspacing = "0px" cellpadding = "0px" border = "1px" bordercolor = "gray">
<?php
$value = 0;
for($col = 0; $col < 8; $col++) {
echo "<tr>";
$value = $col;
for($row = 0; $row < 8; $row++) {
if($value%2 == 0) {
echo
"<td height=40px width=20px bgcolor=black></td>";
$value++;
}
else {
echo
"<td height=40px width=20px bgcolor=white></td>";
$value++;
}
}
echo "</tr>";
}
?>
You could use str_repeat:
<table width="270px" cellspacing="0" cellpadding="0" border="1px" bordercolor="gray">
<?php
$td = '<td height="40px" width="20px" bgcolor=';
$black = "$td'black'></td>";
$white = "$td'white'></td>";
echo str_repeat("<tr>" . str_repeat($black . $white, 4) . "</tr><tr>"
. str_repeat($white . $black, 4) . "</tr>", 4);
?>
</table>
One solution is to use build-in loops derived from some functions, here array_walk(only to avoid explicit for).But it the end the algorithm is the same. It's only a trick !
<?php
$arr = array_fill(0,64,1);
array_walk($arr,"construct");
array_walk($arr,"display");
function construct(&$item, $key)
{
$color=$key%2;
$i=($key-$key%8)/8 + 1;
if($i%2==0)
$color = ($color+1)%2;
$color = $color%2==0 ? "white" : "black";
$j=$key%8+1;
$item = new Square($i,$j,$color);
}
function display($item, $key)
{
if($key%8==0) echo "<br>";
echo $item." ";
}
class Square
{
public $i;
public $j;
public $color;
public function __construct($i,$j,$color)
{
$this->i=$i;
$this->j=$j;
$this->color=$color;
}
public function __toString()
{
return "[".$this->i.",".$this->j."]=".($this->color);
}
}
?>
Output:
[1,1]=white [1,2]=black [1,3]=white [1,4]=black [1,5]=white [1,6]=black [1,7]=white [1,8]=black
[2,1]=black [2,2]=white [2,3]=black [2,4]=white [2,5]=black [2,6]=white [2,7]=black [2,8]=white
[3,1]=white [3,2]=black [3,3]=white [3,4]=black [3,5]=white [3,6]=black [3,7]=white [3,8]=black
[4,1]=black [4,2]=white [4,3]=black [4,4]=white [4,5]=black [4,6]=white [4,7]=black [4,8]=white
[5,1]=white [5,2]=black [5,3]=white [5,4]=black [5,5]=white [5,6]=black [5,7]=white [5,8]=black
[6,1]=black [6,2]=white [6,3]=black [6,4]=white [6,5]=black [6,6]=white [6,7]=black [6,8]=white
[7,1]=white [7,2]=black [7,3]=white [7,4]=black [7,5]=white [7,6]=black [7,7]=white [7,8]=black
[8,1]=black [8,2]=white [8,3]=black [8,4]=white [8,5]=black [8,6]=white [8,7]=black [8,8]=white
For html grid, just adapt display.
function displayHtml($item, $key)
{
if($item->i==1 && $item->j==1)
echo '<table width="270px" cellspacing="0" cellpadding="0" border="1px" bordercolor="gray">';
if($item->j%8==1)
echo "<tr>";
echo "<td height=40px width=20px style='background-color:".$item->color."'></td>";
if($item->j%8==0)
echo "</tr>";
if($item->i==8 && $item->j==8)
echo "</table>";
}

Having some diffculty parsing tree data in ul li format in php

i'm try to create trial balance i somehow achieve tree view in my array and now i want to print my code but don't know how to make tree because i don't know how many children i can get in future and i'm not very good at recursion below is my tree prepared array and i also attach my result that i can make via foreach loop but stuck in children node i can make children nodes via foreach but the problem is it's not a best approach to follow so please help me out to print my tree structure data as per my array. Any help would be appreciated.
Here my tree array look like : Tree Array
My result look like this this is only root nodes of an array and i using jstree to show hierarchy.
<?
$total_opening_debit = 0;
$total_opening_credit = 0;
$total_debit = 0;
$total_credit = 0;
foreach($this->trees as $key => $value)
{
foreach($value as $tree)
{
if($tree["id"] != "")
{
?>
<li>
<span class="first"><? echo $tree["name"]; ?></span>
<span class="other">
<?
if ($tree["opening_debit"] > $tree["opening_credit"])
{
echo format_currency($tree["opening_debit"] - $tree["opening_credit"], 2) . " Dr.";
}
elseif ($tree["opening_credit"] > $tree["opening_debit"])
{
echo format_currency($tree["opening_credit"] - $tree["opening_debit"], 2) . " Cr.";
}
else
{
echo "0";
}
$total_opening_debit += $tree["opening_debit"];
$total_opening_credit += $tree["opening_credit"];
?>
</span>
<span class="other">
<?
if($tree["period_debit"]<>"" && $tree["period_debit"]<>"0")
{
echo format_currency($tree["period_debit"], 2);
$total_debit += $tree["period_debit"];
}
else
{
echo 0;
}
?>
</span>
<span class="other">
<?
if($tree["period_credit"]<>"" && $tree["period_credit"]<>"0")
{
echo format_currency($tree["period_credit"], 2);
$total_credit += $tree["period_credit"];
}
else
{
echo 0;
}
?>
</span>
<span class="other">
<?
if ($tree["opening_debit"] + $tree["period_debit"] > $tree["opening_credit"] + $tree["period_credit"])
{
$closing = format_currency($tree["opening_debit"] + $tree["period_debit"] - $tree["opening_credit"] - $tree["period_credit"], 2) . " Dr.";
}
elseif ($tree["opening_credit"] + $tree["period_credit"] > $tree["opening_debit"] + $tree["period_debit"])
{
$closing = format_currency($tree["opening_credit"] + $tree["period_credit"] - $tree["opening_debit"] - $tree["period_debit"], 2) . " Cr.";
}
else
{
$closing = "0";
}
echo $closing;
//calculate all opeing and closing debit & credit.
if ($tree["opening_debit"] + $tree["period_debit"] > $tree["opening_credit"] + $tree["period_credit"])
{
$total_closing_debit += ($tree["opening_debit"] + $tree["period_debit"] - $tree["opening_credit"] - $tree["period_credit"]);
}
if ($tree["opening_credit"] + $tree["period_credit"] > $tree["opening_debit"] + $tree["period_debit"])
{
$total_closing_credit += ($tree["opening_credit"] + $tree["period_credit"] - $tree["opening_debit"] - $tree["period_debit"]);
}
?>
</span>
<?
if(count($tree["children"]) > 0)
{
//make_children_tree();
}
?>
</li>
<?
}
}
}
?>
i solved myself here what approach i choose i extract children array into other array and on that array i use my recursion to do magic.
<? $array = $trial_tree["children"]; ?>
$trial_balance_tree = $this->trees;
$total_opening_debit = 0;
$total_opening_credit = 0;
$total_debit = 0;
$total_credit = 0;
$total_closing_debit = 0;
$total_closing_credit = 0;
$total_opening = 0;
$total_closing = 0;
function makeListItems($a) {
global $total_opening_debit,$total_opening_credit,$total_credit,$total_debit,$total_closing_debit,$total_closing_credit,$total_opening,$total_closing;
$out = '';
foreach($a as $val) {
//print_r($key); echo is_array($val);exit;
if($val["id"] > 0)
{
$out .= '<li>';
$out .= "<span class='first'>" . $val["name"] . "</span>";
$out .= "<span class='other'>";
if ($val["opening_debit"] > $val["opening_credit"])
{
$out .= format_currency($val["opening_debit"] - $val["opening_credit"], 2) . " Dr.";
}
elseif ($val["opening_credit"] > $val["opening_debit"])
{
$out .= format_currency($val["opening_credit"] - $val["opening_debit"], 2) . " Cr.";
}
else
{
$out .= "0";
}
$total_opening_debit += $val["opening_debit"];
$total_opening_credit += $val["opening_credit"];
$out .= "</span>";
$out .= "<span class='other'>";
if($val["period_debit"]<>"" && $val["period_debit"]<>"0")
{
$out .= format_currency($val["period_debit"], 2);
$total_debit += $val["period_debit"];
}
else
{
$out .= 0;
}
$out .= "</span>";
$out .= "<span class='other'>";
if($val["period_credit"]<>"" && $val["period_credit"]<>"0")
{
$out .= format_currency($val["period_credit"], 2);
$total_credit += $val["period_credit"];
}
else
{
$out .= 0;
}
$out .= "</span>";
$out .= "<span class='other'>";
if ($val["opening_debit"] + $val["period_debit"] > $val["opening_credit"] + $val["period_credit"])
{
$closing = format_currency($val["opening_debit"] + $val["period_debit"] - $val["opening_credit"] - $val["period_credit"], 2) . " Dr.";
}
elseif ($val["opening_credit"] + $val["period_credit"] > $val["opening_debit"] + $val["period_debit"])
{
$closing = format_currency($val["opening_credit"] + $val["period_credit"] - $val["opening_debit"] - $val["period_debit"], 2) . " Cr.";
}
else
{
$closing = "0";
}
$out .= $closing;
//calculate all opeing and closing debit & credit.
if ($val["opening_debit"] + $val["period_debit"] > $val["opening_credit"] + $val["period_credit"])
{
$total_closing_debit += ($val["opening_debit"] + $val["period_debit"] - $val["opening_credit"] - $val["period_credit"]);
}
if ($val["opening_credit"] + $val["period_credit"] > $val["opening_debit"] + $val["period_debit"])
{
$total_closing_credit += ($val["opening_credit"] + $val["period_credit"] - $val["opening_debit"] - $val["period_debit"]);
}
$out .= "</span>";
if(array_key_exists('children', $val)) {
$out .= makeList($val['children']);
}
$out .= '</li>';
}
}
return $out;
}
function makeList($a) {
$out = '<ul>';
$out .= makeListItems($a);
$out .= '</ul>';
return $out;
}
?>
<table style="width:100%;background-color: #A5C6DB;">
<tr>
<th class="table_first" style="width:42.5%;">Ledger Name</th>
<th class="table_other" style="width:14.7%;">Opening</th>
<th class="table_other" style="width:14.7%;">Debit</th>
<th class="table_other" style="width:14.7%;">Credit</th>
<th class="table_other" style="width:15%;">Closing</th>
</tr>
</table>
<?
echo "<div id='trial_balance_tree'>";
echo makeList($trial_balance_tree);
echo "</div>";
Now my view look like this and thats exactly i want.

PHP+Jquery - displaying values in a table

Good evening.
This construction displays the values in a table that sorts them in alphabetical order.Those for example, if you click on the D link, only the names with letter D should be shown, and so on.
PHP code:
<?php
include ('engine/api/api.class.php');
$table = 'dle_post';
$fields = 'xfields';
$where = 'approve=1';
$multirow = 1;
$start = 0;
$limit = 0;
$xfield = 'actor';
$time = '14000';
$tr_new = 0;
$xfields = $dle_api->load_from_cache ($fields, $time, $xfields);
if( !$xfields ) {
$xfields = $dle_api->load_table ($table,$fields,$where,$multirow,$start,$limit);
$dle_api->save_to_cache ( xfields, $xfields);
}
$stack = array();
foreach($xfields as $value){
if($value[xfields]){
$row = xfieldsdataload($value[xfields]);
if($row[$xfield]){
$rowdata = explode( ",", $row[$xfield]);
foreach($rowdata as $value){
if($value){
$value = trim($value);
array_push($stack, $value);
asort($stack);
}
}
}
}
}
$stack = array_count_values($stack);
foreach($stack as $key => $count){
if($tr_new === 0){
echo '<tr class="new">';
}
echo "<td class='blok'>";
echo "<a href=/" . $xfield . "/";
echo $key;
echo " target='_blank' rel='noopener'>";
echo $key;
echo "</a>";
echo "<span>";
echo "(" . $count . ")";
echo "</span>";
echo "</td>";
$tr_new++;
if($tr_new === 1){
echo '</tr>';
$tr_new = 0;
}
}
JQuery:
$(function () {
var _alphabets = $('.alphabet > a');
var _contentRows = $('#countries-table tbody tr');
_alphabets.click(function () {
var _letter = $(this), _text = $(this).text(), _count = 0;
if(_text == 'all') _text = '.';
_alphabets.removeClass("active");
_letter.addClass("active");
_contentRows.hide();
_contentRows.each(function (i) {
var _cellText = $(this).children('td').eq(0).text();
if (RegExp('^' + _text).test(_cellText)) {
_count += 1;
$(this).fadeIn(400);
}
});
});
});
In page:
<div class="alphabet">
<a class="first" href="#">All</a>
A
B
C
...
<a class="last" href="#">Z</a></div>
<div id="conutries">
<table id="countries-table">
<tbody>
{include file="/code.php"}
</tbody>
</table>
</div>
</div>
Everything works fine, but I encounter such a problem - it turns out correctly to output only one value in one line tr ...
When I try to put a 4 td values to the tr line if($tr_new === 4) - they are not sort by alphabetically, they just displayed like this:
Whats wrong? What need to make this code work fine for me?
Thank you in advance for your help!

creating a moustache.js html template using JSON

I just learned about moustache.js and i am attempting to create an HTML template. However, the documentation is a bit hard to decipher. I found a good site that explains partials (which I believe I will need). I was hoping someone might be able to just 'get me started' on how I would need to do this.
I have a php file that I need to convert to the template:
PHP:
<div id='board'>
<?php
if ($threads)
{
$count = count($threads);
$perpage = 17;
$startlist = 3;
$numpages = ceil($count / $perpage);
if ($page == 'home') {$page = 1;}
$threadstart = ($page * $perpage) - $perpage;
$i = 0;
echo "<table class='board'>
<tr>
<th width='5%'><img src='".base_url()."img/board/icons/category_icon.png' alt='category_icon'/></th>
<th width='5%'>Tag</th>
<th width='50%'>Subject</th>
<th width='7.5%'>Author</th>
<th width='7.5%'>Replies/Views</th>
<th width='15%'>Last Post</th>
</tr>";
foreach ($threads as $list)
{ $i++;
$thread_owner = $this->thread_model->get_owner($list['owner_id']);
$thread_id = $list['thread_id'];
$query = $this->db->query("SELECT f.tag FROM filter_thread AS ft
INNER JOIN filter AS f ON ft.filter_id = f.filter_id
WHERE thread_id = $thread_id");
$result = $query->result_array();
$trunc_body = $this->thread_model->get_reply_summary($thread_id);
$filter = "";
$filter2 ="";
$ent = "entertainment";
foreach ($result as $string)
{
if ($string['tag'] == $ent) {
$filter2 .= "<div id='entertainment'><p>";
$filter2 .= "<img src='".base_url()."img/board/icons/entertainment_icon.png' title='Entertainment' alt='Entertainment'/>";
$filter2 .= "</p></div>";
} else {
$filter2 .= "<div id='misc'><p>";
$filter2 .= "<img src='".base_url()."img/board/icons/misc_icon.png' title='Misc' alt='Misc'/>";
$filter2 .= "</p></div>";
$filter .= " [".$string['tag']."]";
}
}
if (!$result) { $filter = "" AND $filter2 =""; }
if ($i > $threadstart AND $i <= $threadstart + $perpage)
{
echo "<tr>";
echo "<td>".$filter2."</td>";
echo "<td>".$filter."</td>";
echo "<td title='".$trunc_body['0']['body']."'>".ucfirst($list['subject'])."<div id='filter'><p></p></div></td>";
echo "<td><p>".$thread_owner."</p></td>";
echo "<td align='right'>Replies: ".$list['replies_num']."<br>Views: ".$list['views']."</td>";
$owner = $this->thread_model->get_owner($list['last_post_id']);
echo "<td>".$owner." <br>".$list['replystamp'] ."</td></tr>";
}
}
echo "</table>";
echo "<br>";
echo "Current Page: $page | ";
echo "Page: ";
for ($n = 1; $n < $numpages+1; $n++)
{
echo "<a href=".base_url()."main/home/$n>$n</a> | ";
}
}
?>
</div>
And here is the AJAX
$(function() {
$('#all').addClass('ui-selected')
$( "#selectable" ).selectable({
selected: updatefilters
});
function updatefilters(ev, ui){
// get the selected filters
var template, html;
var $selected = $('#selectable').children('.ui-selected');
// create a string that has each filter separated by a pipe ("|")
var filters = $selected.map(function(){return this.id;}).get().join("\|");
$.ajax({
type: "POST",
url: 'updatefilters',
dataType: 'json',
data: { filters: filters },
success: function(data){
var template = "<div id ='board'>TESTING{{#body}}<table>";
var partials = "{{#subject}}";
//for (i=0 ; i< data.length ; i++)
//{html += "<tr><td>" + data[i].subject + "</td><td>" + data[i].body + "</td></tr>";}
//html += "</table></div>";
var html = Moustache.to.html(template, data, partials);
$('#board').html(html);
}
});
}
});
Im not sure how to navigate through the JSON array with moustache..and as it is, it does not update the page, though the commented out parts DO.
Thanks in advance!
First of all if you are receiving a json string you will need to to parse it (use $.parseJSON(data))
Once you have the data parsed you need to loop throught the JSON attributes.
For example:
If JSON has the following: body: {content: [dataObj:{data:'a'}, dataObj[data:'b']]}
do
<div>{{#body}}<div>
<div>{{#content}}<div>
<div>{{#dataObj}}<div>
<span>{{data}}<span>
If you are using partial, you will need to call them inside the main template.
Check the moustache5 documentation, it has improved a lot.

Ajax mouseover show function alignment

I am trying to open a box by using mouseover function, however the box always shows on the right part of the object. Hence when the object is right end of the page, the whole box cannot be seen as shown in this photo.
https://rapidshare.com/files/998669066/problem.png
Here is my ajax code:
$(document).ready(function() {
$('.date-available').click(function() {
alert($(this).attr('id'));
});
$('.rezerve-td').mouseover(function() {
$(this).children().show();
}).mouseout(function() {
$(this).children().hide();
});
});
What should i do in order prevent it? Thanks.
Here is the html part of my code:
require_once 'class.dates.php';
require_once 'class.generic.php';
require_once 'connection.php';
$query = mysql_query("SELECT * FROM egitim_salonu", $baglanti);
while ($row = mysql_fetch_object($query)) {
$salonlar[$row->id] = array('ad' => $row->ad, 'detay' => $row->detay);
}
$query = mysql_query("SELECT * FROM salon_rezervasyonu", $baglanti);
while ($row = mysql_fetch_object($query)) {
$rezervasyonlar[$row->salon_id.'%'.$row->gun.'%'.$row->tip] = array('salon_id' => $row->salon_id, 'gun' => $row->gun, 'tip' => $row->tip, 'rezerve_edildigi_egitim' => $row->rezerve_edildigi_egitim);
}
$month = date('m', strtotime($_POST['d']));
$year = date('Y', strtotime($_POST['d']));
$date = date('F Y', strtotime('01-'.$month.'-'.$year));
if ($month == 1 || $month == 3 || $month == 5 || $month == 7 || $month == 8 || $month == 10 || $month == 12) {
$numberOfDays = 31;
} else if ($month == 4 || $month == 6 || $month == 9 || $month == 11) {
$numberOfDays = 30;
} else if (date('L', strtotime($year.'-01-01'))) {
$numberOfDays = 29;
} else {
$numberOfDays = 28;
}
// Tabloyu aç, başlığı hazırla
$output = '<table class="calendar" id="salon-rezervasyon-table">
<thead>
<tr><th rowspan="2">Salon</th><th colspan="'.(2 * $numberOfDays).'">'.$date.'</th></tr>
<tr>';
for ($i = 1; $i <= $numberOfDays; $i++) {
$output .= '<th width="10" colspan="2" class="day-th">'.$i.'</th>';
}
// Başlığı kapat, gövdeyi aç
$output .= '</tr></thead><tbody>';
// Her salon için...
foreach ($salonlar as $salonKey => $salonValue) {
$output .= '<tr id="salon-'.$salonKey.'"><td class="calendar-salon-column">'.$salonValue['ad'].'<br />'.$salonValue['detay'].'</td>';
// ... o ay içindeki günleri kontrol et. Burada kontrol için şunu yapıyoruz: salon id'si, tarih ve gün içerisindeki saati (öğleden önce, öğleden sonra)
// birleştirerek bir index (bu index unique bir index) oluşturuyoruz ve bu index yukarıdaki rezervasyonlar dizisinde tanımlanmış mı diye kontrol ediyoruz.
for ($i = 1; $i <= $numberOfDays; $i++) {
$dateCheck = date('Y-m-d', strtotime($i.'-'.$month.'-'.$year));
$rIndexOO = $salonKey.'%'.$dateCheck.'%Öğleden önce';
$rIndexOS = $salonKey.'%'.$dateCheck.'%Öğleden sonra';
//Öğleden önce
if(isset($rezervasyonlar[$rIndexOO])) {
$egitimPlaniQuery = mysql_query("SELECT * FROM egitim_plani WHERE id = ".$rezervasyonlar[$rIndexOO]['rezerve_edildigi_egitim'], $baglanti);
$egitimPlani = mysql_fetch_object($egitimPlaniQuery);
$output .= '<td id="'.$dateCheck.'%o" class="calendar-td rezerve-td">';
$output .= '<div class="rezerve">'.date('d-m-Y', strtotime($dateCheck)).' Öğleden Önce<br /><br />'.$egitimPlani->egitim_adi.'</div>';
$output .= '</td>';
} else {
$output .= '<td id="'.$dateCheck.'%o" class="date-available calendar-td">';
$output .= '';
$output .= '</td>';
}
//Öğleden sonra
if(isset($rezervasyonlar[$rIndexOS])) {
$egitimPlaniQuery = mysql_query("SELECT * FROM egitim_plani WHERE id = ".$rezervasyonlar[$rIndexOO]['rezerve_edildigi_egitim'], $baglanti);
$egitimPlani = mysql_fetch_object($egitimPlaniQuery);
$output .= '<td id="'.$dateCheck.'%s" class="calendar-td rezerve-td">';
$output .= '<div class="rezerve">'.date('d-m-Y', strtotime($dateCheck)).' Öğleden Sonra<br /><br />'.$egitimPlani->egitim_adi.'</div>';
$output .= '</td>';
} else {
$output .= '<td id="'.$dateCheck.'%o" class="date-available calendar-date-separator">';
$output .= '';
$output .= '</td>';
}
}
$output .= '</tr>';
}
$output .= '</tbody></table>';
echo $output;
You could probably fix this with some css.
div.rezerve {
position: absolute
}
If it still shows up off the page, you can add something like this to your javascript
....
var doc_width = $(document).width();
var rezerve_child = $(this).children();
rezerve_child.show();
var position = rezerve_child.offset();
var rezerve_child_width = rezerve_child.width();
if (position.left + rezerve_child_width > doc_width) {
$(this).css('right', '2px');
}
....
The jQuery Tooltip plugin would also probably be helpful.
http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/

Categories