Jump to content

Recommended Posts

Hi All,

 

I'm converting my search page to all jquery.  Prior to JQuery, each search and page change refreshed the entire page and used a URL query string.  Now that I don't have a query string, I'm stuck...

 

Every thing is working perfectly as far as searching and bringing back the correct results, but the pagination is still looking to use query strings.  Please help :)

 

JQuery Code:

function searchButton() {
$('#results').hide();
$.post('app_index_data.php', { lastname: document.form2.lastname_txt.value },
	function(output) {
		$('#results').html(output).fadeIn(2000);
	});
}

 

This is my HTML from the main index.php page, where everything should be inserted

<div id="results"></div> <!-- END RESULTS DIV -->

 

 

This is my data.php file that the main PHP file calls.  The current pagination is from the tutorial on this site, so it may look familiar...

<?php
session_start();
require_once('../../connect3.php'); 
require_once('../../config3.php');

if(isset($_POST['lastname']))
{
$lastname = mysqli_real_escape_string($connect, $_POST['lastname']);
}

if(isset($lastname) && empty($lastname))
{
echo 'Error';
}
elseif(!empty($lastname))
{
	$links = '';

	$sql1  = "SELECT COUNT(*) FROM applications a LEFT JOIN personal p ON a.app_id = p.app_id WHERE a.client_id = '".$_SESSION['client_id']."' AND a.archived = '0' ";
	$sql1 .= "AND a.deleted_on IS NULL AND p.lastname LIKE '".addslashes($lastname)."%'";


	$result = mysqli_query($connect,$sql1);
	$r = mysqli_fetch_row($result);
	$numrows = $r[0];
	$rowsperpage = 2;
	$totalpages = ceil($numrows / $rowsperpage);


	if(isset($page_currentpage) && is_numeric($page_currentpage))	{$currentpage = (int) $page_currentpage;}
		else{$currentpage = 1;}

	if($currentpage > $totalpages)	{$currentpage = $totalpages;}
	if($currentpage < 1)			{$currentpage = 1;}

	$offset = ($currentpage - 1) * $rowsperpage;



	$sql2  = "SELECT a.status, a.app_id, a.created_on, a.viewed_on, p.firstname, p.lastname, p.email, p.phone, a.pay_date FROM applications a ";
	$sql2 .= "LEFT JOIN personal p ON a.app_id = p.app_id WHERE a.client_id = '".$_SESSION['client_id']."' AND a.deleted_on IS NULL AND a.archived = '0' ";
	$sql2 .= "AND p.lastname LIKE '".addslashes($lastname)."%' ORDER BY a.app_id DESC LIMIT $offset, $rowsperpage";

	$result = mysqli_query($connect, $sql2);



	if(mysqli_num_rows($result) < 1)
	{
		$results1 = '<table width="99%" border="0" align="center" cellpadding="3" cellspacing="0">';
		$results1 .= '<tr>';
		$results1 .= '<td width="12%" height="25" align="center" class="resultsHeader">Actions</td>';
		$results1 .= '<td width="14%" align="center" class="resultsHeader"><a href="#">Date</a></td>';
		$results1 .= '<td width="25%" align="center" class="resultsHeader"><a href="#">Name</a></td>';
		$results1 .= '<td width="14%" align="center" class="resultsHeader">Phone Number</td>';
		$results1 .= '<td width="25%" align="center" class="resultsHeader"><a href="#">Email Address</a></td>';
		$results1 .= '<td width="10%" align="center" class="resultsHeader"><a href="#">Fee Status</a></td>';
		$results1 .= '</tr>';
		$results1 .= '</table>';

		$results1 .= '<table width="99%" align="center" border="0" cellpadding="2" cellspacing="0" class="resultsMiddle">';
		$results1 .= '<tr>';
		$results1 .= '<td align="center" height="25px"><strong><font color="maroon">0 Records Found</font></strong></td>';
		$results1 .= '</tr>';
		$results1 .= '</table>';
		$results1 .= '<table align="center" width="99%" border="0" cellpadding="2" cellspacing="0" class="resultsFooter">';
		$results1 .= '<tr>';
		$results1 .= '<td height="8" width="100%"></td>';
		$results1 .= '</tr>';
		$results1 .= '</table>';
	}
		else
		{
			$results1 = '';
			$color_id = 1;

			$results1 .= '<form id="form1" name="form1" method="post" action="">';
			$results1 .= '<table width="99%" border="0" align="center" cellpadding="3" cellspacing="0">';
			$results1 .= '<tr>';
			$results1 .= '<td width="12%" height="25" align="center" class="resultsHeader">Actions</td>';
			$results1 .= '<td width="14%" align="center" class="resultsHeader"><a href="#">Date</a></td>';
			$results1 .= '<td width="25%" align="center" class="resultsHeader"><a href="#">Name</a></td>';
			$results1 .= '<td width="14%" align="center" class="resultsHeader">Phone Number</td>';
			$results1 .= '<td width="25%" align="center" class="resultsHeader"><a href="#">Email Address</a></td>';
			$results1 .= '<td width="10%" align="center" class="resultsHeader"><a href="#">Fee Status</a></td>';
			$results1 .= '</tr>';
			$results1 .= '</table>';
			$results1 .= '</form>';

			while($row = mysqli_fetch_array($result))
			{
				$status				= $row['status'];
				$id					= $row['app_id'];
				$viewed_on			= $row['viewed_on'];

					if($viewed_on == NULL)
					{
						$application_date	= '<strong>'.substr($row['created_on'],5,2).'/'.substr($row['created_on'],8,2).'/'.substr($row['created_on'],0,4).'</strong>';
						$application_name	= '<strong>'.$row['lastname'] . ', ' . $row['firstname'].'</strong>';
						$email				= '<strong>'.$row['email'].'</strong>';
						$phone				= '<strong>'.$row['phone'].'</strong>';
					}
						else
						{
							$application_date	= substr($row['created_on'],5,2).'/'.substr($row['created_on'],8,2).'/'.substr($row['created_on'],0,4);
							$application_name	= $row['lastname'] . ', ' . $row['firstname'];
							$email				= $row['email'];
							$phone				= $row['phone'];
						}



								if($status == 'Approved')
								{
									if($color_id % 2 == 0)	{$bg = '#f6fff4';}
										else				{$bg = '#EDFFE8';}
								}
									elseif($status == 'Pending')
									{
										if($color_id % 2 == 0)	{$bg = '#fffff2';}
											else				{$bg = '#FFFFD5';}
									}
									elseif($status == 'Declined')
									{
										if($color_id % 2 == 0)	{$bg = '#fef9f9';}
											else				{$bg = '#FFECEC';}
									}
								else
								{
									if($color_id % 2 == 0)	{$bg = '#f9fafe';}
										else				{$bg = '#f0f3ff';}
								}


				$sql = "SELECT * FROM app_activity WHERE app_id = '".$id."'";
				$com_result = mysqli_query($connect, $sql);

					if(mysqli_num_rows($com_result) < 1)
					{
						$com_id = '';
						$com_icon = '';
						$iconTable = 0;
					}
						else
						{
							$iconTable = 1;
							$com_row = mysqli_fetch_array($com_result);

								$com_id		=	 $com_row['comment_id'];
								$com_icon	=	"<a href='edit.php?id=".$id."&s=comments'>".
												'<img src="../img/apps/comments.png" title="View Comments" alt="View Comments" "border="0" /></a>';
						}


					$del_text = '<input type="checkbox" name="checkbox[]" id="checkbox" value="'.$id.'" />';

$print	=	"<a href='print.php?id=".$id."'>".
		'<img src="../img/general/pdf.png" alt="Print Application" width="23" height="23" border="0" title="Print Application" /></a>';

$edit	=	"<a href='edit.php?id=".$id."&s=personal'>".
		'<img src="../img/general/edit1.png" title="Edit Application" alt="Edit Application" width="22" height="23" border="0" /></a>';


// GETS PAYMENT INFORMATION -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
$paydate	= $row['pay_date'];

if(!empty($paydate))
{
$pay_status = '<img src="../img/general/yes_check.png" title="Paid on '.$paydate.'" alt="Paid on '.$paydate.'" border="0" />';
}
else
{
	$pay_status = '<img src="../img/general/no_check.png" title="Not Paid" alt="Not Paid" border="0" />';
}
// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

				$results1 .= '<table width="99%" align="center" border="0" bgcolor="'.$bg.'" cellpadding="2" cellspacing="0" class="resultsMiddle">';
				$results1 .= '<tr>';
				$results1 .= '<td width="12%" align="center">';

					if($iconTable == 1)
					{
						$results1 .= '<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">';
						$results1 .= '<tr>';
						$results1 .= '<td width="25%" align="center">'.$del_text.'</td>';
						$results1 .= '<td width="25%" align="center">'.$print.'</td>';
						$results1 .= '<td width="25%" align="center">'.$edit.'</td>';
						$results1 .= '<td width="25%" align="center">'.$com_icon.'</td>';
						$results1 .= '</tr>';
						$results1 .= '</table>';
					}
						else
						{
							$results1 .= '<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">';
							$results1 .= '<tr>';
							$results1 .= '<td width="25%" align="center">'.$del_text.'</td>';
							$results1 .= '<td width="25%" align="center">'.$print.'</td>';
							$results1 .= '<td width="25%" align="center">'.$edit.'</td>';
							$results1 .= '<td width="25%" align="center"></td>';
							$results1 .= '</tr>';
							$results1 .= '</table>';
						}

				$results1 .= '</td>';
				$results1 .= '<td width="14%" align="center">'.$application_date.'</td>';
				$results1 .= '<td width="25%" align="center">'.$application_name.'<FONT color="maroon"><small><small> (ID:'.$id.')</small></small></FONT></td>';
				$results1 .= '<td width="14%" align="center">'.$phone.'</td>';
				$results1 .= '<td width="26%" align="center">'.$email.'</td>';
				$results1 .= '<td width="10%" align="center">'.$pay_status.'</td>';
				$results1 .= '</tr>';
				$results1 .= '</table>';

				$color_id ++;
			}
		$results1 .= '<table align="center" width="99%" border="0" cellpadding="2" cellspacing="0" class="resultsFooter">';
		$results1 .= '<tr>';
		$results1 .= '<td height="8" width="100%"></td>';
		$results1 .= '</tr>';
		$results1 .= '</table>';

		$range = 5;


		if($currentpage > 1)
		{
			$prevpage = $currentpage - 1;
			$links .= "<a href=".$_SERVER['PHP_SELF'].'?lastname='.$lastname.'&currentpage='.$prevpage.'>Prev</a>';
		}
			else
			{
				$prevpage = $currentpage - 1;
				$links .= '<a>Prev</a>';
			}



for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++)
{
if(($x > 0) && ($x <= $totalpages))
{
	if($x == $currentpage)	{$links .= '<font color="black">  <b>'.$x.'</b>  </font>';}
		else
		{
			$links .=	"<a href=".$_SERVER['PHP_SELF'].'?lastname='.$lastname.'&currentpage='.$x.'><font color="#1f5a9d"> <b>'.$x.'</b> </font></a>';
		}
}
}

		if($currentpage != $totalpages)
		{
			$nextpage = $currentpage + 1;
			$links .= "<a href=" . $_SERVER['PHP_SELF'] . '?lastname='.$lastname.'&currentpage=' . $nextpage . '>Next</a>';
		}
			else
			{
				$links .= '<a>Next</a>';
			}
}
}

if(isset($links) && $links != '')
{
echo '<div id="pagination">';
echo '<table width="99%" border="0" align="center" cellpadding="5" cellspacing="0">';
echo '<tr>';
echo '<td class="link1" align="right">'.$links.'</td>';
echo '</tr>';
echo '</table>';
echo '</div> <!-- END PAGINATION DIV -->';
}

echo $results1;
?>

Link to comment
https://forums.phpfreaks.com/topic/242458-jquery-pagination-conversion/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.