我需要找到一種方式來獲得A HREF從這個HREF /箱開關需要幫助
<a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a> ";
去像
<a href='index.php?menukey=7... then currentpage=1'>First</a>";
我需要一個分頁頁面的開關打開案例區域。以下代碼是我對分頁頁面的要求。任何幫助,將不勝感激。
謝謝
<?php
require_once ('mysqli_connect.php');
$sql = "SELECT COUNT(NewCustomerID) FROM customer";
$result = @mysqli_query($dbc, $sql);
$r = @mysqli_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows/$rowsperpage);
// get the current page or set a default
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 current page is greater than total pages...
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
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$q = "SELECT CONCAT(left(FirstName,1),left(MiddleName,1),LastName) AS UserName,
CONCAT(LastName, ', ', FirstName, ' ', MiddleName) AS Name,
(NewCustomerID) AS customerid,
(OldCustomerID) AS oldcustomerid,
(zlu_birthmonth.Description) AS birthmonth,
(zlu_cars.Description) AS cartype,
(zlu_carcolor.Description) AS carcolor,
(zlu_computers.Description) AS computer,
(zlu_race.Description) AS race,
(zlu_residence.Description) AS residence,
(IsLaptop) AS IsLaptop,
CASE IsLaptop
WHEN '1' THEN 'Yes'
WHEN '0' THEN 'No'
END AS laptop
FROM customer
INNER JOIN zlu_cars ON(customer.CarID = zlu_cars.CarID)
INNER JOIN zlu_birthmonth ON(customer.BirthMonthID = zlu_birthmonth.BirthMonthID)
INNER JOIN zlu_carcolor ON (customer.CarColorID = zlu_carcolor.CarColorID)
INNER JOIN zlu_computers ON (customer.ComputerID = zlu_computers.ComputerID)
INNER JOIN zlu_race ON(customer.RaceID = zlu_race.RaceID)
INNER JOIN zlu_residence ON(customer.ResidenceID = zlu_residence.ResidenceID)
order by NewCustomerID LIMIT $offset, $rowsperpage";
$result = @mysqli_query($dbc, $q); if(!$result){die(mysqli_error($dbc));}
echo '<table border="1">
<tr>
<th>Customer ID</th>
<th>Old Customer ID</th>
<th>Customer Name</th>
<th>UserName</th>
<th>Car</th>
<th>Car Color</th>
<th>Birth Month</th>
<th>Computer Brand</th>
<th>Laptop</th>
<th>Race</th>
<th>Residence</th>
</tr>';
$bg = '#eeeeee'; // set initial back ground color
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$bg = ($bg =='#eeeeee' ? '#ffffff' : '#eeeeee'); // switch the background color.
echo '<tr bgcolor="' . $bg . '">
<td>' . $row['customerid']. '</td>
<td>' . $row['oldcustomerid']. '</td>
<td>' . $row['Name'].'</td>
<td>' . $row['UserName'].'</td>
<td>' . $row['cartype'].'</td>
<td>' . $row['carcolor'].'</td>
<td>' . $row['birthmonth'].'</td>
<td>' . $row['computer'].'</td>
<td>' . $row['laptop'].'</td>
<td>' . $row['race'].'</td>
<td>' . $row['residence'].'</td>
</tr>'; } // end of while loop
echo '</table>';
?>
<?php
/****** build the pagination links ******/
// range of num links to show
$range = 3;
if($currentpage==1)
{
echo '<span class="prn"> First <<</span> ';
}
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'> < </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'>$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'> > </a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Last</a> ";
} // end if
else
{
echo '<span class="prn"> Last >></span> ';
}
/****** end build pagination links ******/
mysqli_close($dbc);
?>
你的問題不是很清楚,你的意思是你怎麼追加其它值的聯繫?比如'index.php?currentpage = 1&menukey = 7'或者你需要幫助才能得到menukey? – Avanche 2012-02-22 10:27:13
Nope Ricardo,將index.php?menukey = 7添加到鏈接。 – 2012-02-22 11:14:03
還是不太清楚我想,你是否想用'index.php?menukey = 7&currentpage = 1'替換'{$ _SERVER ['PHP_SELF']}?currentpage = 1'是它嗎? – Avanche 2012-02-22 12:48:59