Jump to content
php.lv forumi

Video list + ajax nestrada


Lancom

Recommended Posts

jquery_pagination.js

$(document).ready(function(){

//Display Loading Image
function Display_Load()
{
    $("#loading").fadeIn(900,0);
	$("#loading").html("<img src='bigLoader.gif' />");
}
//Hide Loading Image
function Hide_Load()
{
	$("#loading").fadeOut('slow');
};


  //Default Starting Page Results

$("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});

Display_Load();

$("#content").load("ap/pagination_data.php?p=1", Hide_Load());



//Pagination Click
$("#pagination li").click(function(){

	Display_Load();

	//CSS Styles
	$("#pagination li")
	.css({'border' : 'solid #dddddd 1px'})
	.css({'color' : '#0063DC'});

	$(this)
	.css({'color' : '#FF0084'})
	.css({'border' : 'none'});

	//Loading Data
	var pageNum = this.id;

	$("#content").load("ap/pagination_data.php?p=" + pageNum, Hide_Load());
});


});

pagination.php

<script type="text/javascript" src="ap/jquery.js"></script>
<script type="text/javascript" src="ap/jquery_pagination.js"></script>
<a href="/videos/" class="menu"><b>Видео</b></a>
<div class="dotted_hr">
</div>
<div id="loading" ></div>
<div id="content" ></div>
<?php
function pagination($count,$perpage) {
   echo "<ul id=\"pagination\">";
   $between = 5;
   $pages = ceil($count/$perpage);
   if($pages<2)
   {
       echo "";
   }
   $page = (empty($_GET['p']) || $_GET['p']<2) ? 1 : $_GET['p'];
   $first = $page >= $between+1 ? $page-$between : 1;
   $last = $page <= $pages-$between ? $page+$between : $pages;
   if($page>1)
   {
       $p.= sprintf('<a href="?p=1">«</a><a href="?p=%d">‹</a>', $page-1);
       }
       for($i=$first;$i<$last;$i++)
       {
           $p.= sprintf('<span%s><a href="?p=%d">%d</a></span>', $page==$i ? ' class="current"' : '', $i, $i);
           }
           if($page<$pages)
           {
               $p.= sprintf('<a href="?p=%d">›</a><a href="?p=%d">»</a>', $page+1, $pages);
           }
           $p.= '</ul>';
           echo $p;
           }
           pagination($count,$perpage);
?>

pagination_data.php

<?php
include('config.php');

$perpage = 2;
$_LIMIT = (!empty($_GET['p']) && $_GET['p']>1)?($_GET['p']*$perpage)-$perpage:0;
$_LIMIT.=", ".$perpage;
$result = mysql_query("SELECT * FROM ".DB_PREFIX."videos ORDER BY id DESC LIMIT ".$_LIMIT."") or die(mysql_error());
$count = mysql_num_rows(mysql_query("SELECT * FROM ".DB_PREFIX."videos"));
while($row = mysql_fetch_array($result))
{
$rows = mysql_fetch_array(mysql_query("SELECT * FROM ".DB_PREFIX."videos WHERE id =  ".$row['id'].""));
printf("
<div class=\"video\">
<div class=\"vf\">
<div class=\"video_box\">
".$row['name']."<br /><img src=\"http://i1.ytimg.com/vi/".$row['embed']."/default.jpg\" alt=\"".$row['name']."\"/>
</div>
</div>
</div>
");
}
mysql_free_result($result);
?>
</table>

<style> 
#loading
{
width: 100%;
position: absolute;
}
li {
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #dddddd;
color:#0063DC;
}
li:hover
{
color:#FF0084;
cursor: pointer;
}
</style>

video est no nexo4et vivodit pagination po strani4no...

 

i vivodit

Warning: Division by zero in ap\pagination.php on line 12

line 12 -> $pages = ceil($count/$perpage);

Link to comment
Share on other sites

bez ajax vis strada perfekti.

tas vins iskatas bez ajax

<?php
function pagination($count,$perpage) {
   echo "<ul id=\"pagination\">";
   $between = 5;
   $pages = ceil($count/$perpage);
   if($pages<2)
   {
       echo "";
   }
   $page = (empty($_GET['p']) || $_GET['p']<2) ? 1 : $_GET['p'];
   $first = $page >= $between+1 ? $page-$between : 1;
   $last = $page <= $pages-$between ? $page+$between : $pages;
   if($page>1)
   {
       $p.= sprintf('<a href="?p=1">«</a><a href="?p=%d">‹</a>', $page-1);
       }
       for($i=$first;$i<$last;$i++)
       {
           $p.= sprintf('<span%s><a href="?p=%d">%d</a></span>', $page==$i ? ' class="current"' : '', $i, $i);
           }
           if($page<$pages)
           {
               $p.= sprintf('<a href="?p=%d">›</a><a href="?p=%d">»</a>', $page+1, $pages);
           }
           $p.= '</ul>';
           echo $p;
           }
           $perpage = 2;
           $_LIMIT = (!empty($_GET['p']) && $_GET['p']>1)?($_GET['p']*$perpage)-$perpage:0;
           $_LIMIT.=", ".$perpage;

           $result = mysql_query("SELECT * FROM ".DB_PREFIX."videos ORDER BY id DESC LIMIT ".$_LIMIT."") or die(mysql_error());
           $count = mysql_num_rows(mysql_query("SELECT * FROM ".DB_PREFIX."videos"));
           while($row = mysql_fetch_array($result))
           {
               $rows = mysql_fetch_array(mysql_query("SELECT * FROM ".DB_PREFIX."videos WHERE id =  ".$row['id'].""));
               printf("
               <div class=\"video\">
               <div class=\"vf\">
               <div class=\"video_box\">
               ".$row['name']."<br /><img src=\"http://i1.ytimg.com/vi/".$row['embed']."/default.jpg\" alt=\"".$row['name']."\"/>
               </div>
               </div>
               </div>
               \r");
               }
               pagination($count,$perpage);
               mysql_free_result($result);
?>

un viņš nemet Division by zero,

bet kad daļu skriptu uz 2 daļam un pievienoju ajax pagination vinš uzreiz nestrada. Tatad es ajax slikti zinu tam man vajag kurš vis pareizi uzkarstis un izlabos tur kļudas. pagination.php un pagination_data.php

Edited by Lancom
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...