I get the following PHP Notice in my opencart log file.
Undefined variable: http_type in /home/AAA/public_html/vqmod/vqcache/vq2-catalog_view_theme_template_product_product.tpl on line 3
Here is what I have in my product.php file's few first few lines
<?php if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$http_type = "https:";} else {$http_type = "http:";}
<!---THIS IS LINE 3---> ?>
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<div class="breadcrumb" xmlns:v="<?php echo $http_type;?>//rdf.data-vocabulary.org/#" id="brd-crumbs" >
<ul>
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li typeof="v:Breadcrumb">
<?php echo $breadcrumb['separator']; ?><a property="v:title" rel="v:url" href="<?php echo $breadcrumb['href']; ?>"><span><?php echo $breadcrumb['text']; ?></span></a></li>
<?php } ?>
</ul>
</div>
Any help is highly appreciated
Firstly, it's just a notice so I expect everything is working as you would expect.
The notice is generated because when the $http_type variable is echoed, it hasn't necessarily been set to anything. If you add $http_type = ''; before the initial if statement, that will get rid of the notice.
Related
everyone!
My website has a list of office contacts being dynamically generated via PHP (partial snippet below). As you can see, each list result/child has a name, address and, on a following div, a google maps frame.
What I'd like to achieve is to call the latest result of the array and have that one NOT TO display the google maps div.
I think I can probably call it with the "end()" command, but I'm not being able to wrap my head around the right way to proceed... Can anyone point me in the right direction, please?
Thank you!
<header id="standardheader">
<div class="wrap">
<nav class="standardsubnav">
<ul class="standardsubnav_list vanilla"><!--
<?php include_partial( 'contact/citynav', array('class' => 'standardsubnav') ); ?>
--></ul>
</nav>
<h1 class="standardpage_title"><?php echo $current->getHeadline(); ?></h1>
</div>
</header>
<div class="wrap">
<section class="">
<ul class="list4 vanilla">
<?php $contacts = $current->getChildren(); ?>
<?php foreach($contacts as $contact): $settings = $contact->getSettings(); ?>
<li class="item4">
<a name="<?php echo $settings['city']; ?>"></a>
<div class="link4">
<div class="link4_inner">
<h2 class="title4"><?php echo $settings['city']; ?></h2><!--
--><address class="address4">
<?php echo $settings['name']; ?><br />
<?php if(isset($settings['address1']) && $settings['address1'] != "") echo $settings['address1'] . '<br />'; ?>
<?php if(isset($settings['address2']) && $settings['address2'] != "") echo $settings['address2'] . '<br />'; ?>
<?php if(isset($settings['address3']) && $settings['address3'] != "") echo $settings['address3'] . '<br />'; ?>
<?php if(isset($settings['address4']) && $settings['address4'] != "") echo $settings['address4'] . '<br />'; ?>
<?php if(isset($settings['phone']) && $settings['phone'] != ""): ?>t. <?php echo $settings['phone']; ?><br /><?php endif; ?>
<?php if(isset($settings['fax']) && $settings['fax'] != ""): ?>f. <?php echo $settings['fax']; ?><br /><?php endif; ?>
<?php if(isset($settings['email']) && $settings['email'] != ""): ?>e. <?php echo $settings['email']; ?><?php endif; ?>
</address>
</div><!--
--><div class="link4_inner">
<?php
$mapurl = (!empty($settings['mapurl'])) ? $settings['mapurl'] : 'https://www.google.com/maps/#' . $settings['latitude'] . ',' . $settings['longitude'] . ',' . $settings['zoom'] . 'z'; ?>
<div class="gmap4" data-gmap="<?php echo htmlspecialchars( '{"lat":"'.$settings['latitude'].'","lng":"'.$settings['longitude'].'", "zoom":"'.$settings['zoom'].'", "mapurl":"'.$mapurl.'"}' ); ?>">
<noscript><?php echo __('Please enable javascript to see the map.'); ?></noscript>
<?php end($contacts)
Count the $contacts array. Then in the foreach loop check if the element beeing currently in the loop is equals the items in the array, if it's equal to the items, it's the last element, then exit the foreach:
$items = count($contacts );
$i = 0;
foreach($contacts as $contact) {
if(++$i === $items ) {
continue;
}
}
I have the below code which works perfectly. When the title is JohnPage, it does not display in the li.
<?php foreach($this->pages AS $page) { ?>
<li <?php echo $page['title'] == ('JohnPage') ? 'style="display:none";' : ''; ?>>
<a<?php echo ($page['active']?' class="active"':'');?> href="<?php echo $page['href'];?>"><?php echo $page['title'];?></a>
</li>
<?php } ?>
However, I want to say: if the title is either JohnPage or MyPage, do not display in the li. I tried the following:
<li <?php echo $page['title'] == ('JohnPage' OR 'MyPage') ? 'style="display:none";' : ''; ?>>
<li <?php echo $page['title'] == ('JohnPage' || 'MyPage') ? 'style="display:none";' : ''; ?>>
Neither works. Thanks for your help.
Instead of putting your conditional statements there. Try it this way.
<?php
foreach($this->pages AS $page) { ?>
<li <?php if($page['title'] == 'JohnPage' || $page['title'] == 'MyPage') { ?>style="display:none<?php } ?>">
<a <?php echo ($page['active']?' class="active"':'') ?> href="<?php echo $page['href'] ?>"><?php echo $page['title'] ?></a>
</li>
<?php
} // end foreach
?>
I have this template file:
<article class="box vest p10">
<h2 class="box_naslov"><?php echo $vst['naslov'] ?></h2>
<p><?php echo word_limiter($vst['opis'], 25) ?></p>
Izmeni Vest
<a role=obrisi href="<?php echo base_url('admin/vesti_delete/' . $vst['id_clanak']) ?>">ObriĊĦi Vest</a>
<?php
$slider = $vst['slider'] == 0 ? 'Ubaci u slider' : 'Izbaci iz slider-a';
$q = $vst['slider'] == 0 ? 'ubaci' : 'izbaci';
?>
<a role=slider href="<?php echo base_url('admin/vesti_slider/' . $vst['id_clanak'] . '?q=' . $q )?>"><?php echo $slider ?></a>
</article>
In my view file I have tried this:
<?php foreach ($vesti_slider as $vst): ?>
<?php $this->load->view('templates/admin/vesti', $vst) ?>
<?php endforeach ?>
I got error - ** Undefined variable: vst**. Is there some way to do this?
You need to pass data to a view as an array (or object), with the key becoming the variable name.
<?php foreach ($vesti_slider as $vst): ?>
<?php $this->load->view('templates/admin/vesti', array('vst' => $vst)) ?>
<?php endforeach ?>
I am trying to echo into a div but I am getting following error:
Notice: Undefined index: count on $SESSION['count']
when $SESSION['error'] is triggered, I am getting following error:
Undefined index: count on $SESSION['error']
when $SESSION['count'] is triggered, I am getting the similar error as above.
Here is the code in PHP.
<?php
if(isset($_SESSION['error'])){
} else {
foreach($_SESSION['search_output'] as $value){
$value['links'];
$value['title'];
$value['page_body'];
$title = $value['title'];
$link = $value['links'];
$body = $value['page_body'];
$search_output .= "<a href='".$link."'>".$title."</a> - $body<br><br>";}
}
?>
<div id="topResult">
<?php echo $_SESSION['error']; unset($_SESSION['error']);?>
<?php echo ($_SESSION['count']); unset($_SESSION['count']);?>
</div>
<div id="searchBox"><?php echo $search_output; ?></div>
Can't i just echo out the results like the $search_output variable?
Use
<?php if(isset($_SESSION['error'])) {echo $_SESSION['error']; unset($_SESSION['error']);} ?>
<?php if(isset($_SESSION['count'])) {echo ($_SESSION['count']); unset($_SESSION['count']);} ?>
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
<!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('Additional Info'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<?php $user =& JFactory::getUser(); ?>
<strong><?php if($extraField->name == "Price" && $user->get('guest') ==1) { ?></strong>
<?php else: ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo ($extraField->type=='date')?JHTML::_('date', $extraField->value, JText::_('K2_DATE_FORMAT_LC')):$extraField->value; ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<div class="clr"></div>
</div>
<?php endif; ?>
What seems to be the problem here? It's giving back an error of Parse error: syntax error, unexpected T_ELSE in.
This is for K2 Extrafield Visibility
You're mixing the if() : and if() { syntaxes. There's one if() { around the middle when everything else uses :.
Debugging tip: The error is very often in one line before the line that the error message points to.
You're mixing up different ways of using if-else statements. In the middle of that code, you open an if statement with a {, and then use else:. You also never close that if.
Change this -
<?php if($extraField->name == "Price" && $user->get('guest') ==1) { ?>
to this -
<?php if($extraField->name == "Price" && $user->get('guest') ==1): ?>