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'];?>'>
Related
I'm making a dynamic menu where each link in my dropdown menu will be directed to a page base on the ID in the HREF link. How can I POST the ID from my link?
Here's my code:
<?php
$lesson_sql = "SELECT * FROM lesson WHERE lessonID = 1";
$lesson_query = mysqli_query($db, $lesson_sql);
$lesson = mysqli_fetch_assoc($lesson_query);
?>
<nav id="navbar">
<ul id="navmenu">
<div class="navmenu">
<li><strong>Catalog</strong><span class="darrow"></span>
<ul class="sub1">
<li>Topic 1
<ul class="sub1_1">
<?php
do {
?>
<li>
<a href="lesson1.1.php?lessonID=<?php echo $lesson['lessonID'];?>">
<?php echo $lesson['lessonName']; ?>
</a>
</li>
<?php
}while ($lesson = mysqli_fetch_assoc($lesson_query));
?>
</ul>
</li>
</ul>
</li>
</div>
</ul>
</nav>
And here is the code from the code above I wanted to get the ID, its beside the href value.
<li><?php echo $lesson['lessonName']; ?></li>
Sorry for my english, I hope you understand me!
in your lesson1.1.php file you can use $_GET to access the id as below.
$id = $_GET["lessonID"];
If you have query string then you use
$_GET['name of control']
i'm trying to store html tag that includes php script.
This is for the navigation menu, i'm trying to display only the menu for a particular user role.
I'm storing it this way
public function edit_module(){
$id = $this->input->post('Module_ID', TRUE);
$update = $this->db->update('ref_modules', array('Module_Name'=>$this->input->post('Module_Name', TRUE),
'Module_Menu'=> htmlspecialchars($this->input->post('Module_Menu')),
'UpdatedBy'=>$this->session->userdata('user_id')), "Module_ID = '$id'");
if($update){
return TRUE;
}
}
For display
<!--Menu-->
<!--================================-->
<div id="mainnav-menu-wrap">
<div class="nano">
<div class="nano-content">
<ul id="mainnav-menu" class="list-group">
<!--Category name-->
<li class="list-header">Navigation</li>
<?php if($this->data['menu']): ?>
<?php foreach($this->data['menu'] as $row): ?>
<?php echo htmlspecialchars_decode($row->Module_Menu); ?>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div> <!-- nano -->
</div><!-- mainnav-menu-wrap -->
<!--================================-->
<!--End menu-->
When i view the source, its fine but when i click the link, special characters are showing.
http://localhost/folderName/%3C?php%20echo%20base_url(%27citizens%27);%20?%3E
Here's a sample value that i am inserting
<li class="<?php echo ($title == 'Citizens' ? 'active-link' : '');?>">
<a href="<?php echo base_url('citizens'); ?>">
<i class="fa fa-user"></i>
<span class="menu-title">
<strong>Citizens</strong>
</span>
</a>
</li>
Any idea guys? Thanks in advance!
Inserting Html into database For Different user role is not the right way. You can use if Conditions To show your Menu for different User roles.
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've got this PHP code:
<div class="connect_wrap <?php echo $this->class; ?> block" <?php echo $this->cssID; ?>>
<?php if(!$this->empty): ?>
<?php foreach($this->entries as $entry): ?>
<div class="entry block <?php echo $entry->class; ?>">
<div class="tab">
<ul class="tabs">
<li class="tab-link current" data-tab="Kunden">Kunden</li>
<li class="tab-link" data-tab="Loesungen">Lösungen</li>
</ul>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM kunden WHERE partner=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Kunden" class="tab-content current">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/kunden-detail/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
<?php
$this->import('Database');
$pName = $entry->field('name')->value();
$result = \Database::getInstance()->prepare("SELECT * FROM solutions WHERE solution_provider=?")->execute($pName);
?>
<?php if($result->numRows):?>
<div id="Loesungen" class="tab-content">
<?php while($result->next()) { ?>
<div class="items">
<a href="{{env::url}}/synaptic-commerce-solution/<?php echo $result->alias; ?>">
<div class="logo">
<img src="<?php $objFile = \FilesModel::findByUuid($result->logo); echo $objFile->path;?>"width="180" height="135">
</div>
</a>
</div>
<?php } ?>
</div>
<?php endif;?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<?php endif;?>
In that code, I've got two DB queries. My problem is, if there is no data for both queries, the div with the class "connect_wrap" should not be displayed.
How can I do that?
Thanks in advance.
do you want to check if the query has data in it and its not empty ? if so try num_rows it will return the number of rows that the query found/affected for example to check if th query returned one or more rows
if($result->num_rows >= 1) {
//do stuf
} else {
// no result found
}
Move the query execution up or preferably: not within the html but in a different file/class. Then add a check before the content_wrap div: if($kundenResult->num_rows >= 1 || $solutionsResult->num_rows >= 1). If you just keep the individual checks like you already have, it will only show the content_wrap div if either or both of the queries return rows of data.
I'm doing a website where I want to show products from a database, and when clicking a product it opens a div with more detail info (without refreshing page or going to another).
The product gallery looks like this:
<div class="item_galery">
<?php
$i=0;
while($info = mysql_fetch_array( $data )){
$titulo = $info['titulo'];
$descr_corta = $info['descr_corta'];
$img_galeria = $info['img_galeria'];
$img_detalle = $info['img_detalle'];
$sub_img1 = $info['sub_img1'];
$sub_img2 = $info['sub_img2'];
$sub_img3 = $info['sub_img3'];
$acabado = $info['acabado'];
$aux_tamaños = $info['medidas'];
$tamaños = explode(" ", $aux_tamaños);
//echo $aux_tamaños.' '.sizeof($tamaños);
$patron_tornillos = $info['patron_tornillos'];
$coleccion = $info['coleccion'];
?>
<div class="item">
<ul><li onclick="mostra_detall(<?php echo $i;?>);"><img alt="" src="<?php echo 'images/llantas/'.$img_galeria; ?>"/></li></ul>
<ul><li class="descr"><span><?php echo $titulo; ?></span></br><?php echo $acabado; ?></li></ul>
</div>
<?php
$i++;
}
?>
in the class item, the first li has a js call function wihic shoud open the detail info. This info looks like:
<div id="detalle" class="llanta_detalle">
<img class="foto_gran" src="<?php echo 'images/llantas/'.$img_detalle; ?>">
<div class="info">
<div class="cerrar"><ul onclick="tanca_detall(<?php echo $i;?>);"><li><img src="images/llantas/icono_cerrar.jpg"></li><li>CERRAR</li></ul><div class="clear"></div></div>
<div class="detalle_titol">
<ul><li id="titol_llanta" class="titol"><?php echo $titulo; ?></li></ul>
<ul><li id="coleccion_llanta" class="coleccion"><?php echo $coleccion; ?></li></ul>
</div>
<div class="clear"></div>
<div class="detalle">
<ul><li class="requadre">ACABADO</li></ul>
<ul><li id="acabado_llanta" class="acabado"><?php echo $acabado; ?></li></ul>
<ul><li class="requadre">PATRON DE TORNILLOS</li></ul>
<ul><li id="tornillos_llanta" class="tornillos"><?php echo $patron_tornillos; ?></li></ul>
</div>
<div class="clear"></div>
<div class="subimagenes"><ul>
<li><a id="fancyBox" href="<?php echo 'images/llantas/'.$sub_img1; ?>"><img src="<?php echo 'images/llantas/'.$sub_img1; ?>"></a></li>
<li><a id="fancyBox" href="<?php echo 'images/llantas/'.$sub_img2; ?>"><img src="<?php echo 'images/llantas/'.$sub_img2; ?>"></a></li>
<li><a id="fancyBox" href="<?php echo 'images/llantas/'.$sub_img3; ?>"><img src="<?php echo 'images/llantas/'.$sub_img3; ?>"></a></li>
</ul></div>
</div>
<div class="clear"></div>
</div>
my problem is that when the div with detail info is open, I need the specific info from the query of that info, so I would need to do a query or somthing again and do it without refreshing the page. How could I do this?
Thanks and sorry for my english
I think that you should use Jquery for this. Here is a link. I gotta go to sleep now, but if you don`t have it done by tomorrow, I will help you! Hope the jquery link helps you though!