i'm in the middle of creating a website and i want to creat a dynamic dropdown menu.The problem is that when i load the entries from the database only the first entry is displayed correctly , the other entries in the menu are displayed as code. I'm using Xamp with PHP 5.3 and HeidiSql.This is my code :
<div id="1" class="mega solidblocktheme">
<div class="column">
<ul>
<li><a href="<?php include('../conect.php'); $result=mysql_query("SELECT * FROM tours");
while($data=mysql_fetch_row($result))
{ echo $data[2]; ?>"> <?php echo $data[1];
echo "</a></li>"; }
mysql_close($con);?>
</ul>
</div>
</div>
Your loop seems to be in the wrong place. Try something like this:
<ul>
<?php include('../conect.php');
$result=mysql_query("SELECT * FROM tours");
while($data=mysql_fetch_row($result))
{
echo '<li><a href="'.$data[2].'">'.$data[1];
echo "</a></li>";
}
mysql_close($con);?>
</ul>
You should not do it this way .
while($data=mysql_fetch_row($result))
{ echo $data[2]; ?>">
echo ""; }
For every loop , you are just adding content and close tags </a> and </li>
But you are not adding start tags for them .
What you can do is , first store your data result in a string
include('../conect.php');
$result=mysql_query("SELECT * FROM tours");
$data=mysql_fetch_row($result);
mysql_close($con);
$list = "";
foreach($data as $data_key) {
$list.= '<li> '.$data[1].' </li>';
}
So now you got your list
After that comes your HTML , just echo your built string
<div id="1" class="mega solidblocktheme">
<div class="column">
<ul>
<?php
echo $list;
?>
</ul>
</div>
</div>
Related
I must add checkbox in Contact form in Magetno (Magento wer. 1.8.1), I searching tutorials on Google but I found solution ... It is easy way to do this ?
Many Thanks
Wojtek
why you don't use the checkout agreements: Just fetch the agreements in file \app\design\frontend\PACKAGE\TEMPLATE\template\contacts\form.phtml by
if (Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
$agreements = Mage::getModel('checkout/agreement')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active', 1);
}
and print out some or all of them like
if ($agreements) {
foreach ($agreements as $_a):
// ID 5 = Datenschutz-Agreement deutsch, ID 6 = Alter-18-Agreement englisch, ID 7 = Datenschutz-Agreement deutsch, ID 8 = Alter-18-Agreement englisch
if ($_a->getId() >= 7 && $_a->getId() <= 8) {
?>
<li>
<div class="checkout-agreements">
<div class="agreement-content"<?php echo ($_a->getContentHeight() ? ' style="height:' . $_a->getContentHeight() . '"' : '')?>>
<?php if ($_a->getIsHtml()):?>
<?php echo $_a->getContent() ?>
<?php else:?>
<?php echo nl2br($this->escapeHtml($_a->getContent())) ?>
<?php endif; ?>
</div>
<p class="agree">
<input type="checkbox" id="agreement-<?php echo $_a->getId()?>" name="agreement[<?php echo $_a->getId()?>]" value="1" title="<?php echo $this->escapeHtml($_a->getCheckboxText()) ?>" class="required-entry checkbox" /><label for="agreement-<?php echo $_a->getId()?>"><?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->escapeHtml($_a->getCheckboxText()) ?></label>
</p>
</div>
</li>
<?php
}
endforeach;
}
That's all!
If there is someone German here: There you will get the full explanation in German!
Best regards
Bastian
In Magento 1 I've always used
$_product->getMediaGallery('images')
But in the source from Magento 2 I see
$productImage = $block->getImage($_product, $image);
echo $productImage->toHtml();
It's only getting the first product image.
How do I get the second or third image (not only the base one)?
GetMediaGallery function doesn't exists?
Step 1 : open list.phtml from Your Theme\Magento_Catalog\templates\product
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
Add above in your phtml file
then add below code in product loop where you want gallery images
<div class="left-carousel">
<div class="product-small-thumbs">
<?php $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());
$images = $product->getMediaGalleryImages();
if($images->count()>0){?>
<div class="carousel carousel-<?php $_product->getId()?>">
<?php
$i = 0;
foreach($images as $child){
$i++;
$productImage = $_imagehelper->init($product, 'product_page_image_large')
->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(81,53)
->getUrl();
$productImagedata = $_imagehelper->init($product, 'product_page_image_large')
->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(285,240)
->getUrl();
if($i==1) continue;
?>
<div class="slide">
<img data-id="smallthumbs-<?php echo $_product->getId();?>" data-img="<?php echo $productImagedata; ?>" src="<?php echo $productImage; ?>"/>
</div>
<?php
}
?>
</div>
<?php
}
?>
</div>
</div>
In my site I need to display breadcrumbs like this.
Home / Search results for: 'laptop' / Lenova G50 Laptop
I am searching any products (like above 'laptop') in site.
After get result I click any products in search result page.
That clicked product view page I need above type of breadcrumbs.
When I click that " Search results for: 'laptop' ", go to that search
result page.
How can i do this ? Any one help me.
try this and get search term and add to it's url and then again generate search url with query
<?php
$urlRequest = Mage::app()->getFrontController()->getRequest();
$urlPart = $urlRequest->getServer('ORIG_PATH_INFO');
if(is_null($urlPart))
{
$urlPart = $urlRequest->getServer('PATH_INFO');
}
$urlPart = substr($urlPart, 1 );
$currentUrl = $this->getUrl($urlPart);
//$controllerName = Mage::app()->getFrontController()->getRequest()->getControllerName();
//$controllerName = ucfirst($controllerName);
$controllerName = str_replace("/", " ", $urlPart);
$controllerName = str_replace("_", " ", $controllerName);
$controllerName = str_replace("-", " ", $controllerName);
$controllerName = ucfirst($controllerName);
?>
<span class="breadcrumbs">
<strong class="float"><?php echo $this->__("You're currently on: ") ?>
</strong>
<ul class="breadcrumbs">
<li class="home">
<a title="<?php echo $this->__('Go to Home Page') ?>" href="<?php echo $this->getUrl() ?>"><?php echo $this->__('Home') ?></a>
</li>
<li> / </li>
<li class="<?php echo strtolower($controllerName) ?>">
<strong><?php echo $this->__($controllerName) ?></strong>
</li>
</ul>
</span>
I have tried Below Code :
<?php
$last_url = $_SERVER['HTTP_REFERER'];
if (strpos($last_url, 'catalogsearch') !== false && Mage::registry('current_product') && strpos($last_url, 'q=') !== false ) {
$base_url = basename($last_url);
$search = explode("&", $base_url);
foreach($search as $value) {
if(strpos($value, 'q=')!== false) {
$search_text = trim(trim(trim($value), "?"), "q=");
}
}
?>
<div class="breadcrumbs">
<ul>
<li>
<?php echo $this->__("Home");?> /
</li>
<li>
<a href="<?php echo $last_url; ?>">
<?php echo $this->__("Search results for : '%s'", urldecode($search_text));?>
</a>
/
</li>
<li><?php echo $this->escapeHtml(Mage::registry('current_product')->getName()); ?></li>
</ul>
</div>
<?php } ?>
Check this link.
I have the following code to display a product on home page of magento. The product get displayed but I cannot click it and go to the products page .
Can some one please suggest what's wrong.
<?php
//Almost Gone Section
asort($catalog);
reset($catalog);
$almostGoneId = key($catalog);
$almostGoneStock = $catalog[$almostGoneId];
$almostGone = Mage::getModel('catalog/product')->load($almostGoneId);
$_categories = $almostGone->getCategoryIds();
$_catarray = array();
foreach ($_categories as $cat)
{
$category = Mage::getModel('catalog/category')->load($cat);
$_catarray[$category['url_path']] = $category['level'];
}
arsort($_catarray);
$_depth = reset($_catarray);
$_uri = key($_catarray);
$url = $this->getUrl($_uri).$almostGone['url_key'].'';
$almost_gone_price = $almostGone['special_price'];
?>
--><div id="almost_gone" class="product-display-block">
<div class="display-block">
<div class="product_display_image">
<img src="<?php echo $this->helper('catalog/image')- >init($almostGone, 'image')
- >constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(718) ?>" alt="<? php echo $almostGone['name'] ?>">
</div>
<div class="transparent_title">
<!-- <span>Almost Gone, Huge Savings</span> --><span class="display_model">Hurry, Almost Gone Only <?php echo str_replace(".00", "",$_coreHelper->currency($almost_gone_price,true,false)); ?></span>
</div>
</div>
<div class="display_info gone-info">
<span>Grab A Bargain Today, Only </span><span class="red"><?php echo *emphasized text*$almostGoneStock ?></span><span> Left</span>
</div>
<div class="gone-na">
<img src="<?php echo $this->getSkinUrl('images/home/gone-na.png') ?>">
</div>`enter code here`
<div class="link-hover"></div>
</div>
Where is your product url ??
$url = $product->getProductUrl() // may be like this
<a href="<?php echo $url;?>"><img src="<?php echo $this->helper('catalog/image')- >init($almostGone, 'image')
- >constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(718) ?>" alt="<? php echo $almostGone['name'] ?>"></a>
I'm new at this and some help will be apprciated.
I'm building a sidebar in a CI-Boilerplate-Project which contains modules (widgets) that i got run with HMVC https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc.
In the sidebar i have a widget that display a friendslist with status online/offline.
The user has the ability to switch the widgets on/off in the managementsection.
In the Profileview:
<aside class="sidebox right">
<?php foreach ($boxes as $boxName => $boxSetting)
{
echo Modules::run($boxName, $boxSetting['box_visible']);
}
?>
</aside>
if box_visible == 1 the widget will be displayed.
Controller:
class Myfriends extends SM_Controller
{
function __construct()
{
parent::__construct();
}
public function index($visible = false)
{
$user = $this->session->userdata('user');
$myf = $this->widget_model->get_friends($user['user_id'], 5);
$data['friends'] = $myf;
if ($visible) $this->load->view('myfriends', $data);
}
}
View:
<html>
<head>
<meta http-equiv="refresh" content="5">
</head>
<body>
<div class="box friendsbox">
<div id="header"><h3><?=$boxTitle?></h3></div>
<div id="boxcontent">
<ul>
<?php foreach ($friends as $friend): ?>
<li>
<div id="thb_img">
<img src="<?=img_thumb($friend['file_path'], 50, 50) ?>" />
</div>
<div id="short_desc">
<a href="<?= site_url('widget_functions/show_user/' . $friend['uu_id']) ?>">
<?= ucfirst($friend['user_name']) . ' ' . ucfirst($friend['user_lastname']) . ' ' ?>
</a>
<?php if ($friend['is_online']): ?>
<span style="color: green">online</span>
<?php endif; ?>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
<div id="footer">ยป mehr</div>
</div>
</body>
</html>
Now, i need to update the friendslist every 1-2 min so i tryed to load the moduleview within an iframe:
<aside class="sidebox right">
<?php foreach ($boxes as $boxName => $boxSetting): ?>
<?php if ($boxName == 'myfriends' && $boxSetting['box_visible'] == 1) { ?>
<iframe src="<?php echo site_url('myfriends/index'); ?>" ></iframe>
<?php
}
else
{
echo Modules::run($boxName, $boxSetting['box_visible']);
}
?>
<?php endforeach; ?>
</aside>
BUT this dose not work! The place of the widget is emtpy.
Do you have any idea how to get that to work?
appreciate your help
I believe the main issue is with the way you initialize the index method. the index method is kinda tricky with parameters in Codeigniter. In my projects, the only way to get the vlues of arguments passed to the index parameters is by using the URI library method $this->uri->segment(n). In other words, I believe that the value of $visible is not properly passing to the index() body
Anyway, I think you should create another method in your MyFriends Class called render() for example, and call it instead of relaying on the index() method. now render() can play nicely with the $visible=false initialization trick.
Hope this helps