Pagination problem needing assistance - php

Hey, I'm trying to add a button that when clicked will grab data from the mysql database and display it with a pagination. However, I can't seem to get it to work properly.
The first main page looks like this:
pagination.php:
<?php
include('config.php');
$per_page = 3;
//Calculating no of pages
$sql = "select * from explore";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$pages = ceil($count/$per_page)
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>
<style>
body { margin: 0; padding: 5; font-family:Verdana; font-size:10px }
a
{
text-decoration:none;
color:#B2b2b2;
}
a:hover
{
color:#DF3D82;
text-decoration:underline;
}
#loading {
width: 100%;
position: absolute;
}
#pagination
{
text-align:center;
margin-left:120px;
}
li{
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #dddddd;
color:#0063DC;
}
li:hover
{
color:#FF0084;
cursor: pointer;
}
td{
border:solid 1px #dddddd;
padding:5px;
}
</style>
<div id="loading" ></div>
<div id="content" ></div>
<ul id="pagination">
<?php
//Pagination Numbers
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
?>
<p id="marketing">MARKETING</p>
</ul>
<br />
<br />
The button above in that page looks like this as you can see:
<p id="marketing">MARKETING</p>
So, when the user clicks this I need it to get the results from the db.
I do this with jquery like this:
$(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("pagination_data.php?page=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("pagination_data.php?page=" + pageNum, Hide_Load());
});
// Editing below.
// Sort content Marketing
$("#pagination p").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("filter_marketing.php?page=" + pageNum, Hide_Load());
});
});
The problem is that does not work for one main reason:
1. PageNum = marketing. I need it to be the numbers like for 'pagination li' above. I do not know how to fix it properly.
In case I'm confusing you, I will try to explain better:
I want to create a button (i.e. Marketing) that when clicked will get the data from the database and display, but I also need the pagination numbers to be 'refreshed' to compensate for the new data.
If you need further explanation, please let me know. Any help would be greatly appreciated. Thank you.

Think you might be looking for index().
var pageNum = $(this).index() + 1;
Keep in mind that index is 0 based, hence the add 1.
This would also be dependent on your html markup because index returns:
an integer indicating the position of the first element within the jQuery object relative to its sibling elements.
EDIT:
So if, when you update the content of #content, you also change the data-page attribute, you can also have that information when you click on #marketing, so you know which page to get.
This would also work if you were to give one of the LI elements a "current-page" class and then get the id of the .current-class LI.
<div id="content" data-page="1"></div>
Js:
//Pagination Click
$("#pagination li").click(function(){
//...
$("#content").load("pagination_data.php?page=" + pageNum, function(){
Hide_Load();
$(this).attr('data-page', pageNum);
});
});
$("#pagination p").click(function () {
//...
var pageNum = $('#content').attr('data-page');
$("#content").load("filter_marketing.php?page=" + pageNum, Hide_Load());
});

Related

How to use only next and previous button in pagination in php

Hello i am having php code for pagination where page number displaying i want to use only
Next and Previous Button How can i achieve this
Here is my code
<?php
session_start();
$con = mysql_connect('localhost', 'root', 'root');
mysql_select_db('Helixcrm', $con);
$per_page = 15;
$select_table = "select * from tbl_site_configs";
$variable = mysql_query($select_table);
$count = mysql_num_rows($variable);
$pages = ceil($count/$per_page)
?>
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Qjuery pagination with loading effect using PHP and MySql</title>
//Scripts
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function Display_Load() {
$("#load").fadeIn(1000, 0);
$("#load").html("<img src='load.gif' />");
}
function Hide_Load() {
$("#load").fadeOut('slow');
};
$("#paginate li:first").not('.page').css({
'color': '#FF0084'
}).css({
'border': 'none'
});
Display_Load();
$("#content").load("pagination.php?page=1", Hide_Load());
<? php $page; ?>
$("#paginate li").not('.page').click(function() {
Display_Load();
$("#paginate li").css({
'border': 'solid #193d81 1px'
}).css({
'color': '#0063DC'
}).removeClass("active");
$(this).css({
'color': '#FF0084'
}).css({
'border': 'none'
}).addClass("active");
var pageNum = this.id;
$("#content").load("pagination.php?page=" + pageNum, Hide_Load());
});
$("#paginate li.page").click(function() {
var page = $(this).attr("data-value");
if (page == "prev") {
var index = $("#paginate li.active").index();
if (index > 1) {
$("#paginate li.active").prev().trigger("click");
} else {
$("#paginate li.active").trigger("click");
}
} else {
var index = $("#paginate li.active").index();
if (index < $("#paginate li").length - 2) {
$("#paginate li.active").next().trigger("click");
} else {
$("#paginate li.active").trigger("click");
}
}
});
});
</script>
<style type="text/css">
#load {
width:30px;
padding-top:50px;
border:0px green dashed;
margin:0 auto;
}
#paginate {
text-align:center;
border:0px green solid;
width:500px;
margin:0 auto;
}
.link {
width:800px;
margin:0 auto;
border:0px green solid;
}
li{
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #193d81;
color:#0063DC;
}
li:hover {
color:#FF0084;
cursor: pointer;
}
</style>
</head>
<body>
<div id="content" ></div>
<div class="link" align="center">
<ul id="paginate">
<li id="" class="page" data-value="prev">Prev</li>
<?php
for($i=1; $i<=$pages; $i++) {
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
<li id="" class="page" data-value="next">Next</li>
</ul>
</div>
<div style="clear:both"> </div>
<div id="load" align="center" ></div>
</body>
</html>
please help me to short out my problem
Any help will be appreciated
If you can't solve your issue, I'd recommend that you don't really need javascript for pagination, it can be achieved purely through PHP (Which is actually really simple to do), I've done it myself for one of my websites using this code example..
http://www.developphp.com/page.php?id=289
Go ahead and check it out if you can't solve this problem out,
Also he produced a video explaining which sections you need to change, and going through what each part of the code does/means:
https://www.youtube.com/watch?v=K8xYGnEOXYc
Im guessing removing the echo wont work because then you have no data elements which have active bound to them.
Try making a .hidden class in your css to hide each of your echoed li elements, that way they can still have active bound to them, but they won't be visible on the DOM
.hidden { display: none; }
Your markup would then look something like this
<li class='next'><li>
<li id="1" class="hidden active">1</li>
<li id="2" class="hidden">2</li>
<li id="3" class="hidden">3</li>
<li class='prev'><li>

Manipulating jquery variables

<html>
<head>
<style>
.messboxcontent { display:none; background: rgba(0,0,0,.4); width: 400px; height: 100px; margin: 50px auto; padding: 15px;}
.mess_name {display: inline-block; cursor: pointer ; vertical-align: middle; width:165px; height:35px; background:blue; bottom:0px; left:144px; margin-right: 16px}
#msg_holder {overflow-x:scroll ;overflow-y: hidden; white-space: nowrap; position:fixed;height:110px; width:100%; background-color:yellow; bottom:0px;}
</style>
<script type="text/javascript" src="jquery.js" ></script>
<script>
$(document).ready( function() {
done();
});
function done() {
setTimeout( function() {
update();
done();
}, 20000);
}
function update() {
$.getJSON("fetch.php", function(data) {
$.each(data.result, function(){
var message = this['message'];
var name = this['name'];
call(name, message);
});
});
};
function call(name, message){
$("#msg_holder").append("<div class='mess_name'>" + name + "<div>");
$(".mess_test").click( function() {
$('div.messboxcontent').html(' name : '+ name + ' Message : ' + message);
$('div.messboxcontent').fadeIn();
return false;
});
}
</script>
</head>
<body>
<div class="messboxcontent"></div>
<div id="msg_holder"></div>
</doby>
</html>
and this is fetch.php file
{"result":[{"message":"this is haha","name":"haha"},{"message":"this is koka","name":"koka"}]}
when ever i click on a blue box that Contain any name, it show up the latest message and name. what i want is when i click on the box that contain haha as a name i want the box that contain message: this is haha,
You need to use append rather than html.
$('div.box').append( message );

Update when dragged and resized Jquery

I got the jquery variables to update the height width and positions when the divs are dragged but I need them to do the same when they are resized....how can I do this? Here is my code that I'm using right now to get the variables and send them to the php document:
<?
$query = mysql_query("SELECT * FROM users WHERE username='derekshull'");
$rows = mysql_fetch_array($query);
$googlewebx = $rows['googlewebx'];
$googleweby = $rows['googleweby'];
$googlewebh = $rows['googlewebh'];
$googlewebw = $rows['googlewebw'];
$googleimagex = $rows['googleimagex'];
$googleimagey = $rows['googleimagey'];
$googleimageh = $rows['googleimageh'];
$googleimagew = $rows['googleimagew'];
$googlenewsx = $rows['googlenewsx'];
$googlenewsy = $rows['googlenewsy'];
$googlenewsh = $rows['googlenewsh'];
$googlenewsw = $rows['googlenewsw'];
$wikix = $rows['wikix'];
$wikiy = $rows['wikiy'];
$wikih = $rows['wikih'];
$wikiw = $rows['wikiw'];
$wolfx = $rows['wolfx'];
$wolfy = $rows['wolfy'];
$wolfh = $rows['wolfh'];
$wolfw = $rows['wolfw'];
$twitterx = $rows['twitterx'];
$twittery = $rows['twittery'];
$twitterh = $rows['twitterh'];
$twitterw = $rows['twitterw'];
?>
<html>
<head>
<style>
.resizable { color: white; width: 1px; height: 1px; padding: 0.1em; bottom: 0; left: 0; }
.resizable h3 { text-align: center; margin: 0; }
</style>
<style>
#set div.resizable {
background: rgba(0, 157, 255, 0.9);
color: black;
float: left;
margin: 0 10px 10px 0;
padding: 0.5em;
}
#set { clear:both; float:left; width: 368px;}
p { clear:both; margin:0; padding:1em 0; }
</style>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script>
function stop(ui, type) {
var pos_x;
var pos_y;
var window_width;
var window_height;
var need;
if (type == 'draggable') {
pos_x = ui.offset.left;
pos_y = ui.offset.top;
window_width = window.innerWidth;
window_height = window.innerHeight;
need = ui.helper.data("need");
} else if (type == 'resizable') {
pos_x = $(ui.element).offset().left;
pos_y = $(ui.element).offset().top;
window_width = window.innerWidth;
window_height = window.innerHeight;
need = ui.helper.data("need");
}
var width;
var height;
if (need == 1) {
width = $("#web").width();
height = $("#web").height();
}
if (need == 2) {
width = $("#image").width();
height = $("#image").height();
}
if (need == 3) {
width = $("#wiki").width();
height = $("#wiki").height();
}
if (need == 4) {
width = $("#twitter").width();
height = $("#twitter").height();
}
if (need == 5) {
width = $("#googlenews").width();
height = $("#googlenews").height();
}
if (need == 6) {
width = $("#wolf").width();
height = $("#wolf").height();
}
console.log(pos_x);
console.log(pos_y);
console.log(width);
console.log(window_width);
console.log(need);
//Do the ajax call to the server
alert(' x:' + pos_x +
' y:' + pos_y +
' ned_id:' + need +
' width:' + width +
' height:' + height +
' window_width:' + window_width +
' window_height:' + window_height);
}
$("#set div").draggable({
stack: "#set div",
preventCollision: true,
containment: $('#main_content'),
stop: function (event, ui) {
stop(ui, 'draggable');
}
});
$(".resizable").resizable({
stop: function (event, ui) {
stop(ui, 'resizable');
}
});
</script>
<meta http-equiv='Content-type' content='text/html;charset=UTF-8'>
<title>15:11 Project | You • Your Community • Your World</title>
</head>
<body>
<form action='' method='post'>
<fieldset><center>
<input type='search' name='q' /><input type='submit' value='Search' name='submit' />
</fieldset></center>
</form>
<div id="main_content" style="position: fixed; bottom: 0; left: 0; width:100.8%; margin:0 auto; height:95.1%; background-color: #ffffff; color: #000000;">
<div id="set">
<?
if(isset($_POST['q'])){
?>
<div id='web' style='overflow:hidden; left: 5%; top: 5%; width: 20%; height: 15%; position:fixed !important;' class='resizable ui-widget-content' data-need='1'>
<?php
enter code here for div 1.
echo "</div>";
}
?>
<?
if(isset($_POST['q'])){
?>
<div id='image' style='overflow:hidden; height: 19%; width: 32%; left: 60%; top: 12%; position:fixed !important;' class='resizable ui-widget-content' data-need='2'><center>
<?php
Enter code here for div 2
echo "</center></div>";
}
?>
<?
if(isset($_POST['q'])){
?>
<div id='wiki' style='overflow:hidden; left: 5%; top: 36%; height: 17%; width: 25%; position:fixed !important;' class='resizable ui-widget-content' data-need='3'>
<?php
Enter div 3.
}
?>
</div>
</div>
</div>
You can attach a function to the stop event...
$(function() {
$( ".resizable" ).resizable({
stop: function(){
// Do your updates here
}
});
});
Working fiddle:
http://jsfiddle.net/zkDHJ/
Resizable function has the same event stop and you can create a function to do what you are doing in draggable stop and call it from resizable stop
http://api.jqueryui.com/resizable/#event-stop
$(function() {
$( ".resizable" ).resizable({
stop: function() {
// call the same function as in draggable event stop
}
});
});
I would recommend creating a function to call from both events such as
function stop(ui, type) {
// your code
}
And then call it from both events:
$( ".resizable" ).resizable({
stop: function(event, ui) {
stop(ui, 'resizable');
)};
$( ".draggable" ).resizable({
stop: function(event, ui) {
stop(ui, 'draggable');
}
)};
EDIT: You see can see this jsfiddle showing you code working:
http://jsfiddle.net/v8efG/1/
There's a difference from the objects returned by draggable and resizable.
Draggable contains an offset property you can just use. Take a look at the wiki:
http://api.jqueryui.com/draggable/#event-stop
And Resizable does not contain offset but it contains element and you can obtain the offset from it. Take a look at the wiki:
http://api.jqueryui.com/resizable/#event-stop
When draggable
pos_x = ui.offset.left;
When resizable
pos_x = $(ui.element).offset().left;

display a desired tab upon clicking a link

I have a facebook bubble notification. If the user would click the View All messages, the messages tab should be opened. How can I achieve this?
this is what I've tried:
<script>
$('.view_applications').click(function(){
$( "#tabs" ).tabs("select", "#tabs-5" );
return true;
});</script>
<div class="bbbbbbb" id="view<?php echo $id; ?>">
<div style="background-color: #F7F7F7; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; position: relative; z-index: 100; padding:8px; cursor:pointer;">
View all <?php echo $comment_count; ?> application/s
</div>
</div>
But it's not displaying the desired tab. Any help is appreciated. Thanks.
You haven't initalized the DOM ?
$(document).ready(function(){
// do your work here
$('.view_applications').click(function(){
$( "#tabs" ).tabs("select", "#tabs-5" );
return false;
});
});
EDIT :
First initialize your tabs when document is ready :
$('#tabs').tabs();
then select your desired tab :
$('.view_applications').click(function(){
$( "#tabs" ).tabs("select", "#tabs-5" );
return false;
});
-----see the return false; ----------

jQuery load google maps

I want to load a google maps file with the jQuery
the logic is very easy i want that the page is reloaded every time that i send a new variables to the query...
the problem is the content doesn't load..
here is the code JavaScript....
<script type="text/javascript">
$(document).ready(function(){
function Display_Load()
{
$("#loading").fadeIn(900,0);
$("#loading").html("<img src='img/bigLoader.gif' style='border:none;' />");
}
//Hide Loading Image
function Hide_Load()
{
$("#loading").fadeOut('slow');
};
$("#pagination li").click(function(){
Display_Load();
$("#content").load("file_map.php", Hide_Load());
}
});
</script>
and here the html code
<body>
<div id="loading" ></div>
<div id="content" ></div>
</body>
this exemple is work well with other file php or html but just still not work with Google Maps i think that the problem is on the initialize() function on loading of page but i don't know how to solve it please who can help me
th'x a lot
There's an error in your JavaScript code, you haven't completed the click call (or the ready call; the nature of syntax errors means we don't really know which one is incomplete). So none of the code is running and you should be seeing a syntax error in the JavaScript console.
Using proper indentation can help you catch errors, it's well worth getting in the habit of doing so. Here's a properly-indented version of your code:
<script type="text/javascript">
$(document).ready(function(){
function Display_Load()
{
$("#loading").fadeIn(900,0);
$("#loading").html("<img src='img/bigLoader.gif' style='border:none;' />");
}
//Hide Loading Image
function Hide_Load()
{
$("#loading").fadeOut('slow');
};
$("#pagination li").click(function(){
Display_Load();
$("#content").load("file_map.php", Hide_Load());
}
});
</script>
As you can (now) see, you're missing the ); on the second-to-last line to complete the click call.
Once you fix that, separately there's an error on this line:
$("#content").load("file_map.php", Hide_Load());
// here -----^^
Just like any other function call, there you're calling Hide_Load and passing its return value into load. If you want Hide_Load to be the completion callback, you don't want to call it, you just want to pass the function reference — ditch the ():
$("#content").load("file_map.php", Hide_Load);
With the (), it's like you're calling $("#content").load("file_map.php", undefined); since the result of a function call to a function that doesn't use return is undefined.
Here the content of an exemple file of google maps file_map.php.....
<?php include_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
require_once($lib_path."mysql.class.php");
require_once($lib_path."document.php");
require_once $lib_path . "userAccount.php";
require_once($lib_path."adsearch_class.php");
?>
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script src="http://maps.google.com/maps?file=api&v=2&key=------------------------------------" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
this file is work well without jQuery...
but no result when i call it with the jQuery..
the index.php file is here
<?php
include_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
require_once($lib_path."mysql.class.php");
require_once($lib_path."document.php");
require_once $lib_path . "userAccount.php";
require_once($lib_path."adsearch_class.php");
$per_page = 5;
//getting number of rows and calculating no of pages
$rsd=new db_publish;
$rsd->connect();
$sql = "SELECT *FROM `table` LIMIT 0 , 30";
$rsd->query($sql);
$counteur = $rsd->count();
$pages = ceil($counteur/$per_page);
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Display Loading Image
function Display_Load()
{
$("#loading").fadeIn(900,0);
$("#loading").html("<img src='img/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("file_map.php");
//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.("#pagination li").id;
$("#content").load("file_map.php?page=" + pageNum);
});
});
</script>
<style>
body { margin: 0; padding: 0; font-family:Verdana; font-size:15px }
a
{
text-decoration:none;
color:#B2b2b2;
}
a:hover
{
color:#DF3D82;
text-decoration:underline;
}
#loading {
width: 100%;
position: absolute;
}
#pagination
{
text-align:center;
margin-left:120px;
}
li{
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #dddddd;
color:#0063DC;
}
li:hover
{
color:#FF0084;
cursor: pointer;
}
</style>
<div align="center">
<div id="loading" ></div>
<div id="content" ></div>
<table width="800px">
<tr><Td>
<ul id="pagination">
<?php
//Show page links
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
</ul>
</Td></tr></table>
</div>
as i tell you on the first time this exemple is work well just with google maps the content can't load....
on the result page i have just
<div id="map_canvas" style="width: 500px; height: 300px"></div>
without the maps content inside

Categories