I have do a pagination with php&html,the problem is my $page is always equal 1 even I click another page and the url is already become ?page=2.The value $p cannot pass as $page.How can I solve this?
<ul class="nospace clear" style="width:1310px;">
<?php
if(isset($_GET['page'])&& $_GET['page']!=""){$page = $_GET["page"];}else{$page=1;}
$current=$page;
$end=12;
if($page=1){$start=0;$previous=$page;$next=$page+1;}
else if($page<=12){$start=$page*12-12;$previous=$page-1;$next=$page+1;}
else{$start=0;$previous=$page-1;$next=12;}
$sql = "Select * from item where Gender='women' AND Category='cloth' LIMIT $start,$end";
$result = mysqli_query($connect,$sql);
while($row=mysqli_fetch_assoc($result)){?>
<img src="../images/demo/<?php echo $row["Pic"]; ?>" style="width:300px;height:280px"><br><p></p><h3><strong><?php echo $row["Name"]; ?></strong></h3><p><?php echo $row["Description"]; ?></p></li>
<?php } ?></ul><figcaption>Page <?php echo"$page ";?> end...</figcaption>
</figure>
</div>
<nav class="pagination">
<ul>
<li>« Previous</li>
<?php
for ($p=1;$p<13;$p++){
if ($page == $p) {?>
<li class="current btn1"><strong><?php echo $p ?></strong></li><?php }
else{?><li><a href="?page=<?php echo $p ?>" class='btn1'><?php echo $p ?></a></li><?php }}?>
<li> Next » </li>
</ul>
I tried to link $child['id'] but can't do it. Link is removed on line 13. Can anyone tell me correct way to generate category link on click?
<!-- fetch parent categories -->
<?php
while ($parent = mysqli_fetch_assoc($parentquery)) : ?>
<?php
$parent_id=$parent['cat_id'];?>
<!--fetch sub-categories-->
<?php
$sql2 = "SELECT * FROM categories WHERE cat_parent = '$parent_id'";
$child_query = $db->query($sql2); // database object
?>
<div class="col-menu col-md-3">
<h6 class="title"><?php echo $parent['cat_name'] ?></h6>
<div class="content">
<ul class="menu-col">
<?php while($child = mysqli_fetch_assoc($child_query)) : ?>
Now I want to link each category on the below. Loops works fine. I am seeing category names but no link. Please help
<li> <a href='#'>
<?php echo $child['cat_name']; ?></a></li>
<?php endwhile; ?>
</ul>
</div>
</div>
<?php endwhile; ?>
You need to pass it in href
<li>
<a href='<?php echo $child['link'];?'>
<?php echo $child['cat_name']; ?>
</a>
</li>
Try this if ur href is empty then you should add
<a href='"<?php echo $child['link'];?>"'> // double quotes
you should pass the id to the href,
<a href='<?=$child['id'];?>'>
I've been trying to display the category name after the contents of the 'Latest' module in Joomla.
I've made the query in phpMyAdmin and it works. But when I try to use this in the php module template page the page stops at the point the php should start.
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery("SELECT `title` FROM `#__categories` WHERE `id` = " .$item->catid);
$category = $db->loadResult();
echo $category;
When I replace $item->catid with a fixed number, it works like it does in phpMyAdmin. Can anyone tell me where I go wrong?
Thanks
$item is already having the category title so no need to get it through a db query. You can simply do this in your tmpl file. You can get the category using $item->category_title
<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) : ?>
<li itemscope itemtype="http://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>-
<b><?php echo $item->category_title; ?></b>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>
UPDATE:
if you want to display as you asked in comments then you need to do this
<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) : ?>
<li itemscope itemtype="http://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php endforeach; ?>
<b>Click here for more news on ("<?php echo $item->category_title; ?>")</b>
</ul>
I am using the ZF1 with Zend_Paginator but if I have a search that brings all data without filter, works perfectly, but if I have a query filter paging works only on the first page.
public function getConsultaTelefones($setor)
{
if ($setor != "") {
$select = $this->select()
->setIntegrityCheck ( false )
->from ( array('t' => 'sca_telefone'))
->joinInner ( array ('p' => 'sca_posto'), 't.idPosto = p.idPosto')
->joinInner ( array ('l' => 'sca_lotacao'), 't.idLotacao = l.idLotacao')
->where("l.idLotacao = ?", $setor) ;
$resultado = $this->fetchAll($select);
} else {
$select = $this->select()
->setIntegrityCheck ( false )
->from ( array('t' => 'sca_telefone'))
->joinInner ( array ('p' => 'sca_posto'), 't.idPosto = p.idPosto')
->joinInner ( array ('l' => 'sca_lotacao'), 't.idLotacao = l.idLotacao');
$resultado = $this->fetchAll($select);
}
return $resultado;
}
In the parameter $ sector it brings all the data as the filter and creates the correct pagination, but only the first page because if I click the next or last page he "recreates" the paging all table data.
public function paginacaoConsulta($dados)
{
$pagina = intval($this->_getParam('pagina', 1));
$paginator = Zend_Paginator::factory($dados);
$paginator->setItemCountPerPage(5);
$paginator->setPageRange(7);
$paginator->setCurrentPageNumber($pagina);
$this->view->paginator = $paginator;
}
public function consultarAction()
{
$setor = $this->_getParam('setor');
$modLotacao = new Sca_Model_Lotacao('sca');
$resultado = $modLotacao->getConsultaTelefones($setor);
$this->paginacaoConsulta($resultado);
}
Already researched several things but nothing has met me. Please I need help.
Follow the rest of the codes:
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'paginacao.phtml'); ?>
<nav>
<ul class="pagination">
<li>
<!-- Link para a primeira página -->
<?php if (isset($this->previous)): ?>
<a title="Primeira Página" href="<?php echo $this->url(array('pagina' => $this->first)); ?>" aria-label="Previous">« Primeira</a>
<?php else: ?>
<a class="current" title="Primeira Página" href="<?php echo $this->url(array('pagina' => $this->first)); ?>" aria-label="Previous">« Primeira</a>
<?php endif; ?>
</li>
<li>
<?php if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('pagina' => $this->previous)); ?>" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
<?php else: ?>
<span aria-hidden="true">«</span>
<?php endif; ?>
</li>
<li>
<?php foreach ($this->pagesInRange as $pagina): ?>
<?php if ($pagina != $this->current): ?>
<a href="<?php echo $this->url(array('pagina' => $pagina)); ?>">
<?php echo $pagina; ?>
</a>
<?php else: ?>
<?php echo $pagina; ?>
<?php endif; ?>
<?php endforeach; ?>
</li>
<li>
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('pagina' => $this->next)); ?>" aria-label="Next" >
<span aria-hidden="true">»</span>
</a>
<?php else: ?>
<span aria-hidden="true">»</span>
<?php endif; ?>
<?php endif; ?>
</li>
<li>
<!-- Última página -->
<?php if (isset($this->next)): ?>
<a title="Última Página" href="<?php echo $this->url(array('pagina' => $this->last)); ?>" aria-label="Next">Última »</a>
<?php else: ?>
<a class="current" title="Última Página" href="<?php echo $this->url(array('pagina' => $this->last)); ?>" aria-label="Next">Última »</a>
<?php endif; ?>
</li>
</ul>
</nav>
You have to pass to query param in next and previous link. Like this:
<a href="<?php echo $this->url(array('pagina' => $this->previous, 'setor' => $this->setor)); ?>" aria-label="Previous">
and pass it to the view:
$this->view->setor = $this->_getParam('setor');
My brain doesn't seem to want to work this morning.. i have the following array:
private $nav_pages = [['0', 'Home', 'home'],
['0', 'About Us', 'about'],
['0', 'Our Services', 'services'],
['1', 'PROCURE TO PAY (P2P)', 'procure'],
['1', 'ORDER TO CASH (02C)', 'cash'],
['1', 'GENERAL ACCOUNTING', 'general'],
['2', 'Charting of Accounts', 'charting'],
['2', 'General Ledger Maintenance', 'maintenance'],
['2', 'Accounts Receivable Services', 'receivable'],
['2', 'Accounts Payable Services', 'payable'],
['2', 'Reconciliation of Bank Accounts and Credit Cards', 'reconciliation'],
['2', 'Preparing Financial Statements', 'statements'],
['2', 'Payroll Processing', 'payroll'],
['1', 'CLOSING & REPORTING', 'closing'],
['0', 'How It Works', 'how-it-works'],
['0', 'Contact Us','contact'],
['0', 'Careers', 'careers']];
This is then fed to a php page which is meant to lay out a multi-layered pure css drop down menu.. the php page code is:
<ul class="<?php echo $ul_class; ?>">
<?php $this_layer = 0;
// place array content into variables
foreach ($links as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
if ($item_layer > $this_layer) { ?>
<ul>
<?php $this_layer++; }
elseif ($item_layer == $this_layer) { ?>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
</li>
<?php }
elseif ($item_layer < $this_layer) { ?>
</li></ul>
<?php $this_layer--; } ?>
<?php } ?>
The output is not correct however as the above code always closes the list item containing the second layer before the second layer is ready to be closed. if that makes sense..
<ul class="pages_nav">
<li class="home">
<a class="home"
href="/home">
Home
</a>
</li>
<li class="about">
<a class="about"
href="/about">
About Us
</a>
</li>
<li class="services">
<a class="services"
href="/services">
Our Services
</a>
</li>
<ul>
<li class="cash">
<a class="cash"
href="/cash">
ORDER TO CASH (02C)
</a>
</li>
<li class="general">
<a class="general"
href="/general">
GENERAL ACCOUNTING
</a>
</li>
<ul>
<li class="maintenance">
<a class="maintenance"
href="/maintenance">
General Ledger Maintenance
</a>
</li>
<li class="receivable">
<a class="receivable"
href="/receivable">
Accounts Receivable Services
</a>
</li>
<li class="payable">
<a class="payable"
href="/payable">
Accounts Payable Services
</a>
</li>
<li class="reconciliation">
<a class="reconciliation"
href="/reconciliation">
Reconciliation of Bank Accounts and Credit Cards
</a>
</li>
<li class="statements">
<a class="statements"
href="/statements">
Preparing Financial Statements
</a>
</li>
<li class="payroll">
<a class="payroll"
href="/payroll">
Payroll Processing
</a>
</li>
</li></ul>
</li></ul>
<li class="contact">
<a class="contact"
href="/contact">
Contact Us
</a>
</li>
<li class="careers">
<a class="careers"
href="/careers">
Careers
</a>
</li>
SOLUTION:
<ul class="<?php echo $ul_class; ?>">
<?php $this_layer = 0;
// place array content into variables
foreach ($links as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
// check if link needs to be manipulated
switch($do) {
case 'strtolower':
$item_string = strtolower($item_string);
break;
case 'strtoupper':
$item_string = strtoupper($item_string);
break;
} ?>
<?php if ($item_layer > $this_layer) { ?>
<ul>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php $this_layer++; }
elseif ($item_layer == $this_layer) { ?>
</li><li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php }
elseif ($item_layer < $this_layer) { ?>
</li></ul></li><li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php $this_layer--; } ?>
<?php } ?>
Never close the the li tag, close it when you add something
foreach ($links as $link) {
if ($item_layer > $this_layer) {
echo '<ul><li> ......';
this_layer++;
}elseif ($item_layer == $this_layer) {
echo '</li><li>......';
}elseif ($item_layer < $this_layer) {
echo '</li></ul><li>......';
$this_layer--;
}
}
Last you probably need to add a echo '</li></ul>' outside of the foreach to close everything
Had to rework the code a little, usually i organize the php menu structure in tree form makes it easier to parse into html menus, but here it is:
<ul class="<?php echo $ul_class; ?>">
<?php
$this_layer = 0;
$closeit = false;
// place array content into variables
foreach ($nav_pages as $link) {
$item_layer = $link[0];
$item_string = $link[1];
$item_link = $link[2];
if ($item_layer > $this_layer) {
// Changing level, dont close the previous li
?><ul><?php
$closeit = false;
$this_layer++;
}
if ($item_layer == $this_layer) {
// Same level, check if you need to close previous li
if ($closeit) {
?></li><?php
}
// Render the li
?>
<li class="<?php echo $item_link; ?>">
<a class="<?php echo $item_link; ?>"
href="/<?php echo $item_link; ?>">
<?php echo $item_string; ?>
</a>
<?php
// Close it on next loop
$closeit = true;
}
elseif ($item_layer < $this_layer) {
// Changing layer back down, close the previous li and the current level ul
?>
</li>
</ul>
<?php
$this_layer--;
}
}
// Finished loop, there should still be a li waiting to be closed
if ($closeit) {
?></li><?php
}
// Close menu
?>
</ul>
Should be working, let me know if it isnt
Suggested php menu structure:
$menu = array(
array(
"url"=>"/place.php",
"text"=>"Go to place"
),
array(
"url"=>"/place2.php", // not necessary
"text"=>"with submenu",
"children"=>array(
array(
"url"=>"/placewithinplace2.php",
"text"=>"submenu item"
)
)
)
);