How to show pagination series with dot in php? - php

code:
<?php
$sql = "SELECT COUNT(*) FROM attandance";
$retval1 = mysqli_query($con, $sql);
$row = mysqli_fetch_row($retval1);
$total_records = $row[0];
$total_pages = ceil($total_records / $limit);
echo "<ul class='pagination'>";
echo "<li><a href='index.php?page=".($page)."' class='button'>Previous</a></li>";
for ($i=1; $i<=$total_pages; $i++) {
echo "<li><a href='index.php?page=".$i."'>".$i."</a></li>";
}
echo "<li><a href='index.php?page=".($page+1)."' class='button'>NEXT</a></li>";
echo "</ul>";
?>
I have create a pagination in php now its work fine but pagination series look like previous 1234567891011121314151617181920 next like this but I want like
Previous 1 2 3 4 5 . . . . 20 next. So, How can I do this ?Please help me.
Thank You

Here is some helpful code for you, please check this.
<?php
// Please place your select query over here.
// $sql = "SELECT COUNT(*) FROM attandance";
// $retval1 = mysqli_query($con, $sql);
// $row = mysqli_fetch_row($retval1);
// $total_records = $row[0];
$page = ((isset($_GET['page'])) && ($_GET['page'] != ''))? $_GET['page'] : 1;
echo "You are on Page: ".$page;
$limit = 5; // I'm all this as static, please change it
$total_records = 34; // I'm all this as static, please change it to `$row[0]`
$total_pages = ceil($total_records / $limit);
echo "<ul class='pagination'>";
if ($page > 1)
echo "<li><a href='index.php?page=".($page - 1)."' class='button'>PREVIOUS</a></li>";
$show = 0;
for ($i = $page; $i <= $total_pages; $i++) {
$show++;
if ($page == $i)
echo "<li class='active'>".$i."</li>";
else if (($show < 5) || ($total_pages == $i))
echo "<li><a href='index.php?page=".$i."'>".$i."</a></li>";
else
echo "<li class='dot'>.</li>";
}
if ($total_pages > $page)
echo "<li><a href='index.php?page=".($page + 1)."' class='button'>NEXT</a></li>";
echo "</ul>";
?>
If you need some CSS, try using:
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {
background-color: #111111;
}
li.active {
display: block;
color: red;
text-align: center;
padding: 16px;
text-decoration: none;
}
li.dot {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
</style>

Related

Including check box to each row of my data in database using php and html

I have a table called idean5 which has my data.And i'm displaying that data using php on my webpage ,now i want to add a tick box for each row of my data,actually i want to move particular rows from this table idean5 to other table called idean4. so when some one ticks the boxes and click on a move hyperlink button.this data should be moved.
code for this:
<?php
include('db.php');
require_once('auth.php'); //include of db config file
include ('paginate.php'); //include of paginat page
$per_page = 15; // number of results to show per page
$result = mysql_query("SELECT * FROM idean5");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);//total pages we going to have
//-------------if page is setcheck------------------//
if (isset($_GET['page'])) {
$page = intval($_GET['page']);
if ($page <= 0){
$page = 1;}
$show_page = $_GET['page']; //it will telles the current page
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
} else {
// error - show first set of results
$start = 0;
$end = $per_page;
}
} else {
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
$tpages=$total_pages;
?>
<!DOCTYPE html>
<html>
<head>
<style>
body { background: #eee url() no-repeat center 0px; padding-top:5px;}
ul {
list-style-type: none;
margin: center;
padding: center;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: green;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<style type="text/css">
.logo
{
text-align: center;
}
.container{
}
</style>
<h3 align="right">WELCOME <?php echo $_SESSION['SESS_FIRST_NAME'];?>!</h3>
</head>
<body>
<ul>
<li>REQUEST FOR TND</li>
<li class="dropdown">
UPLOAD TND
<div class="dropdown-content">
TND REQUESTS
UPLOAD TND
</div>
</li>
<li>STATUS SEARCH</li>
<li>SEARCH</li>
<li>APPROVAL</li>
<li>LOGOUT</li>
</ul>
<div class="container">
<div class="row">
<div class="logo">
</a>
</div>
</div>
<div class="row">
<?php
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
echo '<div class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
}
echo "</ul></div>";
// display data in table
echo "<table border='1'>
<tr>
<th>TND ID</th>
<th>Site Name S1</th>
<th>Site Name S2</th>
<th>Idea ID S1</th>
<th>Idea ID S2</th>
<th>O N M Remarks</th>
<th>Planning Remarks</th>
<th>Projects Remarks</th>
</tr>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++) {
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) {
break;
}
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'TND_ID') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Site_name_S1') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Site_name_S2') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Idea_ID_S1') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Idea_ID_S2') . '</td>';
if (mysql_result($result, $i, 'O_M_Remarks')) {
echo '<td>' . mysql_result($result, $i, 'O_M_Remarks').'</td>';
}
else {
echo '<td>' . mysql_result($result, $i, 'O_M_Remarks') . 'O N M remarks </td>';
}
if (mysql_result($result, $i, 'Planning_Remarks')) {
echo '<td>' . mysql_result($result, $i, 'Planning_Remarks').'</td>';
}
else {
echo '<td>' . mysql_result($result, $i, 'Planning_Remarks') . 'Planning remarks </td>';
}
if (mysql_result($result, $i, 'O_M_Remarks')) {
echo '<td>' . mysql_result($result, $i, 'Projects_Remarks').'</td>';
}
else {
echo '<td>' . mysql_result($result, $i, 'Projects_Remarks') . 'Projects remarks </td>';
}
echo "</tr>";
}
// close table>
echo "</table>";
// pagination
?>
</div>
</div>
</div>
</div>
</body>
</html>
In "//echo out the contents of each row into a table" portion. try this at this.
<td>input type="checkbox"></td>
For loop will automatically add checkbox in each row.

PHP showing menu tree in dropdown list

Function to menu tree:
function category_tree($parent_id)
{
$sql = "SELECT * FROM menu WHERE parent_id ='".$parent_id."'";
$result = $conn->query($sql);
echo "<div id=\"wrapper\">
<div id=\"navmenu\">";
while($row = mysqli_fetch_object($result)):
$i = 0;
if ($i == 0) echo '<ul>';
echo '<li>' . $row->name;
category_tree($row->id);
echo '</li>';
$i++;
if ($i > 0) echo '</ul>';
endwhile;
echo "</div>
</div>";
}
The CSS file:
#navmenu {
margin: 0;
padding: 0;
}
#navmenu ul{
margin: 0;
padding: 0;
height:30px;
}
#navmenu li{
margin: 0;
padding: 0;
list-style: none;
float: left;
position: relative;
background:#09F;
}
#navmenu ul li a{
text-align:center;
text-decoration:none;
font-family:Arial, Helvetica, sans-serif;
height:30px;
width:150px;
display:block;
color:#000066;
padding-top:7px;
}
#navmenu ul ul{
position:absolute;
visibility: hidden;
top:30px;
}
#navmenu ul li:hover ul {
visibility:visible;
}
#navmenu li:hover {
background:#3366CC;
}
#navmenu ul li:hover ul li a:hover{
background:#03C;
color:#FFFFFF;
}
Database for recursive menu:
The result is without using div element (id=wrapper,id=navmenu) is working well, see:
When i put back div elements (id=wrapper,id=navmenu), its not happen what i want:
I want: when my cursor on "Felso menu" show the dropdown menu (Sport, Ekszer, Egyeb), and if my cursor on "Foci" show the dropdown menu (Mezek, Egyeb, Utok, Labdak), etc... Any ideas how can I do that, or how to fix my code?
Ok. I sloved this problem, here is my code:
function get_menu_tree($parent_id)
{
global $conn;
$menu = "";
$sqlquery = " SELECT * FROM menu where parent_id='" .$parent_id . "' ";
$res=mysqli_query($conn,$sqlquery);
while($row=mysqli_fetch_array($res,MYSQLI_ASSOC))
{
$menu .="<li><a href='".$row['link']."'>".$row['name']."</a>";
$menu .= "<ul>".get_menu_tree($row['id'])."</ul>"; //call recursively
$menu .= "</li>";
}
return $menu;
}

CSS: Overflow in a DIV horizontally

I'm developing an application that contains a table made ​​by div. The divs are filled according to the results database.
As you can see in the image below.
However, if I put one more item on the bench, just disrupting the entire table. What I would do is to put a rod horizontally so that it could rotate it and so see the other items in the database without messing up the structure.
CODE
CSS
#fundo {
display: block;
height: 550px;
margin-left: -3%;
overflow: scroll;
overflow-y: hidden;
width: 1150px;
}
.vacina, .dose, .aplicacao {
background-color: #D3D3D3;
border-radius: 5px;
float: left;
height: 90px;
margin-top: 6px;
margin-left: 6px;
position: relative;
width: 100px;
}
.vacina {
height: 50px;
}
PHP
include_once ("db.php");
$sql = "SELECT nomeVacina FROM vacina ORDER BY cod";
$ds1=mysql_query($sql);
if ($ds1) {
if (mysql_num_rows($ds1) > 0) {
$x = 0;
///////////////////////////////////////////////
////////////////// DIV VACINA /////////////////
while($linha=mysql_fetch_assoc($ds1)) {
$x++;
if(!($linha['nomeVacina'] == "Outras")) {
echo "<div class='vacina' id='".$x."'>";
echo "<br>".$linha['nomeVacina'];
echo "</div>";
}
}
}
///////////////////////////////////////////////
////////////////// FIM DIV VACINA /////////////
///////////////////////////////////////////////
////////////////// DIV DOSE ///////////////////
for($i = 1; $i < 6; $i++) {
echo "<br><br><br><br><br><br>";
echo "<div class='dose'>";
if($i == 4 || $i == 5) {
echo "<br>Reforco";
}
else {
echo "<br>Dose ".$i;
}
echo "</div>";
///////////////////////////////////////////////
////////////////// FIM DIV DOSE ///////////////
///////////////////////////////////////////////
////////////////// DIV APLICACAO //////////////
$z=0;
for($j = 1; $j <= $x; $j++) {
$sql2 = "SELECT DATE_FORMAT(dataAplicacao, '%d/%m/%Y') AS dataAplicacao, loteVacina, descricaoVacina FROM vacinaaplicada WHERE dose = ".$i." AND codigoVacina = ".$j." AND codPaciente = '".$cns."'";
$ds2=mysql_query($sql2);
$linha2=mysql_fetch_assoc($ds2);
$z++;
echo "<div class='aplicacao' id='".$z.$i."'>";
if($linha2 == "") {
echo "";
}
else {
echo "<div style='margin-top:10px;'>". $linha2['descricaoVacina']."<div class='fonte'><b>Data</b><br></div>". $linha2['dataAplicacao'] . "<div class='fonte'><b>Lote</b><br></div>".$linha2['loteVacina']."</div>" ;
}
echo "</div>";
}
///////////////////////////////////////////////
////////////////// FIM DIV APLICACAO /////////////
}
As you can see in the previous image, has 9 div class Vacina.
If I add a div class Vacina the most, will mess up the table.
What I'd like is to insert more than 9 div class Vacina causing the background div (div class includes all div) increase in width, but leaving it the same way the image, just putting a scroll bar horizontally to display whole div.
If I understood you correctly, I'd try this:
To #fundo, add
white-space: nowrap;
And I replaced float: left; with:
display: inline-block;
Maybe that's what you're looking for.
EDIT:
Okay, I've built an example from scratch (but using javascript, not php, I can't test php atm): JSFiddle.
It's a bit messy but you should be able to code it in PHP if you like to.
Let me know if you've got trouble with this.
EDIT 2:
Just to have it in the answer (not just in its comments), the final solution is: this JSFiddle.
HTML + PHP
<?php
include_once("sessao.php");
if (!isset($_SESSION['funcionario']['cpfFuncionario'])) {
header("Location:index.html");
}
else if($_SESSION['funcionario']['adicionarDireito'] == 0) {
header("Location:funcionario.php");
}
?>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<title>Vacina Digital - Cadastrar Vacinação</title>
<script type="text/javascript" src="template/js/script.js"></script>
<link rel="stylesheet" href="template/css/reset.css">
<link rel="stylesheet" href="template/css/fonts.css">
<style>
body {
background-color: #fdfdfd;
overflow-y: auto;
}
#form {
margin-left: 50px;
padding-left: 7%;
padding-top: 50px;
padding-bottom: 10px;
margin-right: 50px;
border: 1px solid #0F935A;
border-radius: 20px;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
#form h1 {
text-align: center;
margin-right: 150px;
font-family: "RobotoCondensed";
font-size: 30px;
}
</style>
</head>
<body>
<?php
include_once 'menufuncionario.php';
?>
<div id="form">
<fieldset>
<?php
include_once("db.php");
if(isset($_POST['cns'])) {
$cns = $_POST['cns'];
$_SESSION['paciente'] = $cns;
}
else{
$cns = $_SESSION['paciente'];
}
$sql = "SELECT *, DATE_FORMAT(dataNascimento, '%d/%m/%Y') AS 'data' FROM populacao WHERE codigoCns = ".$cns;
$ds1=mysql_query($sql);
if ($ds1) {
if (mysql_num_rows($ds1) > 0) {
$sql2 = "SELECT * FROM vacinaaplicada WHERE codPaciente = ".$cns;
$ds2 = mysql_query($sql2);
$linha=mysql_fetch_assoc($ds2);
$linha2=mysql_fetch_assoc($ds1);
$data_nasc = $linha2['data'];
$data_nasc=explode("/",$data_nasc);
$data=date("d/m/Y");
$data=explode("/",$data);
$anos=$data[2]-$data_nasc[2];
if ($data_nasc[1] > $data[1]) {
$anos = $anos-1;
} if ($data_nasc[1] == $data[1]) {
if ($data_nasc[0] <= $data[0]) {
$anos = $anos;
} else {
$anos = $anos-1;
}
} if ($data_nasc[1] < $data[1]) {
$anos = $anos;
}
$data2=date("d/m/Y");
echo "<h1>Carteira de Vacinação - ".$linha2['nomeCrianca']."</h1>";
/*echo "
<div id='caderneta' style='margin-left:-6%'>
";*/
include_once 'caderneta.php';
echo "
</div>";
} else {
echo "<h1>CNS Inválido</h1><br><br>
<center><a href='javascript:window.history.go(-1)'><button style='margin-left:-150px' class='button button-red' href='javascript:window.history.go(-1)'>Voltar</button></a></center>
";
}
}
?>
</div>
</body>
</html>
Caderneta
<html>
<head>
<link rel="stylesheet" href="template/css/fonts.css">
<style type="text/css">
#fundo {
min-width: 800px;
display: block;
overflow: scroll;
overflow-y: hidden;
margin-left: -3%;
height: 550px;
white-space: nowrap;
}
#pinguim, .vacina, .dose, .aplicacao {
width: 100px;
height: 90px;
background-color: #D3D3D3;
margin-top: 6px;
margin-left: 6px;
border-radius: 5px;
position: relative;
float: left;
}
#pinguim, .vacina {
height: 50px;
}
.vacina, .dose{
background: green;
font-family: RobotoCondensed;
font-size: 14pt;
text-align: center;
color: #ffffff;
}
.vacina{
padding-top: -14px;
line-height: 15px;
}
.dose, .aplicacao{
margin-top: -32px;
}
.dose{
line-height: 29px;
}
.aplicacao, .fonte {
font-family: "RobotoLight";
text-align: center;
}
</style>
</head>
<body>
<div id = "fundo">
<div id = "pinguim">
</div>
<?php
include_once ("db.php");
$sql = "SELECT nomeVacina FROM vacina ORDER BY cod";
$ds1=mysql_query($sql);
if ($ds1) {
if (mysql_num_rows($ds1) > 0) {
$x = 0;
$k = 0;
while($linha=mysql_fetch_assoc($ds1)) {
$x++;
if(!($linha['nomeVacina'] == "Outras")) {
echo "<div class='vacina' id='".$x."'>";
echo "<br>".$linha['nomeVacina'];
echo "</div>";
}
}
for($i = 1; $i < 6; $i++) {
echo "<br><br><br><br><br><br>";
echo "<div class='dose'>";
if($i == 4 || $i == 5) {
echo "<br>Reforco";
}
else {
echo "<br>Dose ".$i;
}
echo "</div>";
$z=0;
for($j = 1; $j <= $x; $j++) {
$sql2 = "SELECT DATE_FORMAT(dataAplicacao, '%d/%m/%Y') AS dataAplicacao, loteVacina, descricaoVacina FROM vacinaaplicada WHERE dose = ".$i." AND codigoVacina = ".$j." AND codPaciente = '".$cns."'";
$ds2=mysql_query($sql2);
$linha2=mysql_fetch_assoc($ds2);
$z++;
echo "<div class='aplicacao' id='".$z.$i."'>";
if($linha2 == "") {
echo "";
}
else {
echo "<div style='margin-top:10px;'>". $linha2['descricaoVacina']."<div class='fonte'><b>Data</b><br></div>". $linha2['dataAplicacao'] . "<div class='fonte'><b>Lote</b><br></div>".$linha2['loteVacina']."</div>" ;
}
echo "</div>";
}
}
echo"</div>";
}
}
?>
</div>
</div>
</body>
</html>

Pagination using ul tag does not work in phone [duplicate]

I have created pagination on my page using ul tag. It is work well when i access by computer, but when i access by phone, it is not work. I can't even click on it. Do you know what is the problem?
Here is the code*
$query_pag_num = "SELECT COUNT(*) AS count FROM request WHERE Req_Status = 'Active' and Req_ID NOT IN(SELECT Req_ID from tweets where U_ID='$userId') ";
if($intcount>0){
$query_pag_num.=" and Re_Type IN(SELECT interest from user_interest where userid='$userId')";
}
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);
/* ---------------Calculating the starting and endign values for the loop----------------------------------- */
if ($cur_page >= 7) {
$start_loop = $cur_page - 3;
if ($no_of_paginations > $cur_page + 3)
$end_loop = $cur_page + 3;
else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
$start_loop = $no_of_paginations - 6;
$end_loop = $no_of_paginations;
} else {
$end_loop = $no_of_paginations;
}
} else {
$start_loop = 1;
if ($no_of_paginations > 7)
$end_loop = 7;
else
$end_loop = $no_of_paginations;
}
/* ----------------------------------------------------------------------------------------------------------- */
$table.="<div id=\"tab_area\">";
$table .= "<div id='page_tab'><ul>";
// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
$table .= "<li p='1' class='active'>First</li>";
} else if ($first_btn) {
$table .= "<li p='1' class='inactive'>First</li>";
}
// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
$pre = $cur_page - 1;
$table .= "<li p='$pre' class='active'>Previous</li>";
} else if ($previous_btn) {
$table .= "<li class='inactive'>Previous</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
if ($cur_page == $i)
$table .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
else
$table .= "<li p='$i' class='active'>{$i}</li>";
}
// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
$nex = $cur_page + 1;
$table .= "<li p='$nex' class='active'>Next</li>";
} else if ($next_btn) {
$table .= "<li class='inactive'>Next</li>";
}
// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
$table.= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
$table .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
}
$table = $table . "</ul></div>
<p class=\"alignC mt10 fontS\">(全3000件中1500件表示)</p>
</div>"; // Content for pagination
echo $table;
Here is CSS code
#page_tab ul li.inactive,
#page_tab ul li.inactive:hover{
display:none;
}
.data ul li{
list-style: none;
font-family: verdana;
margin: 5px 0 5px 0;
color: #000;
font-size: 13px;
}
#page_tab{
width: 500px;
margin: 20px auto 0 auto;
text-align: center;
font-size: 0.8em;
font-style: normal;
height: 25px;
}
#page_tab ul li{
list-style: none;
display:inline;
border: 1px solid #006699;
padding: 2px 6px 2px 6px;
margin: 0 3px 0 3px;
font-family: arial;
font-size: 14px;
color: #006699;
font-weight: bold;
background-color: #f2f2f2;
}
#page_tab ul li:hover{
color: #fff;
background-color: #006699;
cursor: pointer;
}
Thank in advance.

pagination in css/php

two questions:
--1-- it displays all the number of pages. but i'd like it to display as:
<< Prev . . 3 4 [5] 6 7 . . Next >>
--2-- when i hover on the current page no, it should change color or increase the font-size, but when i modify the css of a:hover, all the page nos change color or size instead of the one which i'm pointing to. also, when modifying a:active, nothing happens.
this is my paging code in php:
$self = $_SERVER['PHP_SELF'];
$limit = 2; //Number of results per page
$numpages=ceil($totalrows/$limit);
$query = $query." ORDER BY idQuotes LIMIT " . ($page-1)*$limit . ",$limit";
$result = mysql_query($query, $conn)
or die('Error:' .mysql_error());
?>
<div class="caption">Search Results</div>
<div class="center_div">
<table>
<?php while ($row= mysql_fetch_array($result, MYSQL_ASSOC)) {
$cQuote = highlightWords(htmlspecialchars($row['cQuotes']), $search_result);
?>
<tr>
<td style="text-align:right; font-size:15px;"><?php h($row['cArabic']); ?></td>
<td style="font-size:16px;"><?php echo $cQuote; ?></td>
<td style="font-size:12px;"><?php h($row['vAuthor']); ?></td>
<td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']); ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="searchmain">
<?php
//Create and print the Navigation bar
$nav="";
$next = $page+1;
$prev = $page-1;
if($page > 1) {
$nav .= "<span class=\"searchpage\"><a onclick=\"showPage('','$prev'); return false;\" href=\"$self?page=" . $prev . "&q=" .urlencode($search_result) . "\">< Prev</a></span>";
$first = "<span class=\"searchpage\"><a onclick=\"showPage('','1'); return false;\" href=\"$self?page=1&q=" .urlencode($search_result) . "\"> << </a></span>" ;
}
else {
$nav .= " ";
$first = " ";
}
for($i = 1 ; $i <= $numpages ; $i++) {
if($i == $page) {
$nav .= "<span class=\"searchpage\">$i</span>";
}else{
$nav .= "<span class=\"searchpage\"><a onclick=\"showPage('',$i); return false;\" href=\"$self?page=" . $i . "&q=" .urlencode($search_result) . "\">$i</a></span>";
}
}
if($page < $numpages) {
$nav .= "<span class=\"searchpage\"><a onclick=\"showPage('','$next'); return false;\" href=\"$self?page=" . $next . "&q=" .urlencode($search_result) . "\">Next ></a></span>";
$last = "<span class=\"searchpage\"><a onclick=\"showPage('','$numpages'); return false;\" href=\"$self?page=$numpages&q=" .urlencode($search_result) . "\"> >> </a></span>";
}
else {
$nav .= " ";
$last = " ";
}
echo $first . $nav . $last;
?>
</div>
and this is how it displays currently:
alt text http://img714.imageshack.us/img714/7184/pag1l.jpg
css:
.searchmain {
margin:30px;
text-align: center;
}
.searchpage {
border: solid 1px #ddd;
background: #fff;
text-align:left;
font-size: 16px;
padding:9px 12px;
color: #FEBE33;
margin-left:2px;
}
.searchpage a{
text-decoration: none;
color: #808080;
}
.searchpage a:hover {
color: #FEBE33;
border-color: #036;
text-decoration: none;
}
.searchpage a:visited {
color: #808080;
}
The solution to your first program seems pretty straightforward; you know the number of surrounding links you want to display so you can simply loop from current_page - surrounding_links to current_page + surrounding_links. Add some conditions for the beginning, the end and for when to show the dots and you're done.
For the css; I´m not entirely sure what you want to achieve but I think you can solve it by using just a tags, the surrounding spans seem redundant, you only need them for the items that are not links (.no_link in the example below):
a, .no_link {
float: left;
display: block;
padding:9px 12px;
border: solid 1px #ddd;
background: #fff;
text-align:left;
font-size: 16px;
}
a {
color: #808080;
}
a:hover {
color: #FEBE33;
border-color: #036;
}
.no_link {
color: #FEBE33;
}
1. Change the padding and border properties of this CSS:
.searchpage {
border: none;
background: #fff;
text-align:left;
font-size: 16px;
padding:3px;
color: #FEBE33;
margin-left:2px;
}
And add the codes for square brackets around $i.
for($i = 1 ; $i <= $numpages ; $i++) {
if($i == $page) {
$nav .= "<span class=\"searchpage\">[$i]</span>";
That should change the visuals of your numbers, I haven't tested it seeing as you don't have a live site but it should work.
2. Instead of .searchpage a:hover try searchmain a:hover.
None of this is tested, but best I could come up with after viewing your code. Hope it helps to at least point you in the right direction :)

Categories