Code: Select all
function onFormSubmit()
{
document.getElementById('cname').value=' ';
}Here is my query- I have pagination applied:
Any suggestions would be greatly appreciated, thanks
Code: Select all
<?php
session_start();
session_destroy();
$criteria = $_GET['sCriteria'];
if(isset($criteria))
{
if($criteria=='')
{
$message = "Please Enter a Criteria";
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('{$message}');
location.href = ' ';
</script>";
return false;
}
include 'connect.php';
$sql = "SELECT COUNT(*) FROM Customers
WHERE
(CUST_Forename LIKE '%$criteria%') OR (CUST_Surname LIKE '%$criteria%')
OR (CUST_Postcode LIKE '%$criteria%')
UNION
SELECT COUNT(*) FROM Company
WHERE (COMP_Name LIKE '%$criteria%')
";
$result=mysql_query($sql) or die(mysql_error());
$result2=mysql_fetch_row($result);
$numrows = $result2[0];
$rowsperpage = 1;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
$offset = ($currentpage - 1) * $rowsperpage;
$sql=" SELECT CUST_ID, CUST_Forename, CUST_Surname,
CUST_Email, CUST_Mobile, CUST_HomeNum,
CUST_AddressL1, CUST_AddressL2, CUST_AddressL3,
CUST_Postcode, '' as COMP_ID, '' as COMP_Name, '' as COMP_Email, '' as COMP_PrimaryNum,
'' as COMP_SecondaryNum, '' as COMP_AddressL1, '' as COMP_AddressL2, '' as COMP_AddressL3,
'' as COMP_Postcode
FROM Customers
WHERE
(CUST_Forename LIKE '%$criteria%') OR (CUST_Surname LIKE '%$criteria%')
OR (CUST_Postcode LIKE '%$criteria%')
UNION
SELECT '' as CUST_ID, '' as CUST_Forename, '' as CUST_Surname, '' as CUST_Email,
'' as CUST_Mobile, '' as CUST_HomeNum, '' as CUST_AddressL1, '' as CUST_AddressL2, '' as CUST_AddressL3,
'' as CUST_Postcode,
COMP_ID, COMP_Name, COMP_Email, COMP_PrimaryNum,
COMP_SecondaryNum, COMP_AddressL1, COMP_AddressL2, COMP_AddressL3,
COMP_Postcode
FROM Company
WHERE (COMP_Name LIKE '%$criteria%')
LIMIT $offset, $rowsperpage
";
$result=mysql_query($sql) or die(mysql_error());
if(!mysql_num_rows($result))
{
$message = "No matching record";
echo "<script language=\"javascript\" type=\"text/javascript\">
alert('{$message}');
location.href = ' ';
</script>";
return false;
}
while($result2=mysql_fetch_assoc($result))
{
$CID = $result2['CUST_ID'];
$cuEmail = $result2['CUST_Email'];
$forename = $result2['CUST_Forename'];
$surname = $result2['CUST_Surname'];
$mobile = $result2['CUST_Mobile'];
$homenum = $result2['CUST_HomeNum'];
$add1 = $result2['CUST_AddressL1'];
$add2 = $result2['CUST_AddressL2'];
$add3 = $result2['CUST_AddressL3'];
$pCode = $result2['CUST_Postcode'];
$compID = $result2['COMP_ID'];
$compName = $result2['COMP_Name'];
$compEmail = $result2['COMP_Email'];
$pNumber = $result2['COMP_PrimaryNum'];
$sNumber = $result2['COMP_SecondaryNum'];
$compAdd1 = $result2['COMP_AddressL1'];
$compAdd2 = $result2['COMP_AddressL2'];
$compAdd3 = $result2['COMP_AddressL3'];
$compPostcode = $result2['COMP_Postcode'];
}//end while
$range = 3;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show First link to go back to page 1
echo "<a href=\"{$_SERVER['PHP_SELF']}?currentpage={1}&sCriteria={$criteria}\">First </a>";
// get previous page num
$prevpage = $currentpage - 1;
// show Previous link to go back to 1 page
echo "<a href=\"{$_SERVER['PHP_SELF']}?currentpage={$prevpage}&sCriteria={$criteria}\">Previous</a>";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo "<a href=\"{$_SERVER['PHP_SELF']}?currentpage={$x}&sCriteria={$criteria}\">$x</a>";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo "<a href=\"{$_SERVER['PHP_SELF']}?currentpage={$nextpage}&sCriteria={$criteria}\">Next </a>";
// echo forward link for lastpage
echo "<a href=\"{$_SERVER['PHP_SELF']}?currentpage={$totalpages}&sCriteria={$criteria}\">Last</a>";
} // end if
}
?>