duplicate values for data from multiple tables in joomla 2.5 - joomla2.5

I am working on MVC component and fetching data from two tables in joomla 2.5 but i had a problem there are different types of fares for flight info so when it display output in table it shows duplicate values here is sample code
Query
$query->select('f.flight_name,f.flight_code,f.flight_dep_date,f.flight_ari_date,f.flight_dep_time,f.flight_ari_time,f.flight_dep_city,f.flight_ari_city,f.flight_child_id,d.flight_id,d.fair_type,d.fair');
$query->from('#__fairinfo as f,#__faredescription as d');
$query->where('f.flight_child_id = d.flight_id');
in view
<?php foreach($this->items as $i => $value):
?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<?php echo $value->flight_child_id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $value->flight_child_id); ?>
</td>
<td><?php echo $value->flight_name; ?></td>
<td><?php echo $value->flight_code; ?></td>
<td><?php echo $value->flight_dep_date; ?></td>
<td><?php echo $value->flight_ari_date; ?></td>
<td><?php echo $value->flight_dep_time; ?></td>
<td><?php echo $value->flight_ari_time; ?></td>
<td><?php echo $value->flight_dep_city; ?></td>
<td><?php echo $value->flight_ari_city; ?></td>
<td><?php
echo $value->fair_type;
echo $value->fair; ?>
</td>
</tr>
<?php endforeach; ?>
here is out put
4 G8-334 G8-334 2012-05-22 2012-05-22 11:10:00 13:05:00 MUMBAI (TERMINAL 1B) NEW DELHI (TERMINAL 1D) GoSmart7,566.00 INR
4 G8-334 G8-334 2012-05-22 2012-05-22 11:10:00 13:05:00 MUMBAI (TERMINAL 1B) NEW DELHI (TERMINAL 1D) GoFlexi7,829.00 INR
4 G8-334 G8-334 2012-05-22 2012-05-22 11:10:00 13:05:00 MUMBAI (TERMINAL 1B) NEW DELHI (TERMINAL 1D) GoBusiness9,718.00 INR
4 G8-334 G8-334 2012-05-22 2012-05-22 11:10:00 13:05:00 MUMBAI (TERMINAL 1B) NEW DELHI (TERMINAL 1D) GOPROMO(ROUNDTRIP)7,136.00 INR
4 G8-334 G8-334 2012-05-22 2012-05-22 11:10:00 13:05:00 MUMBAI (TERMINAL 1B) NEW DELHI (TERMINAL 1D) GoSpecial Sold out/Not
rows 4 is printing 5 times as there are five types of fares

please do like this
$query->select('f.flight_child_id,f.flight_name,f.flight_code,f.flight_dep_date,f.flight_ari_date,f.flight_dep_time,f.flight_ari_time,f.flight_dep_city,f.flight_ari_city,f.flight_child_id');
$query->from('#__fairinfo as f');
In view
<?php foreach($this->items as $i => $value):
?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<?php echo $value->flight_child_id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $value->flight_child_id); ?>
</td>
<td><?php echo $value->flight_name; ?></td>
<td><?php echo $value->flight_code; ?></td>
<td><?php echo $value->flight_dep_date; ?></td>
<td><?php echo $value->flight_ari_date; ?></td>
<td><?php echo $value->flight_dep_time; ?></td>
<td><?php echo $value->flight_ari_time; ?></td>
<td><?php echo $value->flight_dep_city; ?></td>
<td><?php echo $value->flight_ari_city; ?></td>
<td><?php
$model = $this->getmodel('Your model name');
echo nl2br($model->functionname($value->flight_child_id));
?></td>
</tr>
<?php endforeach; ?>
Model function
functionname($id) {
$db = JFactory::getDBO();
$query->select('d.flight_id,d.fair_type,d.fair');
$query->from('#__faredescription as d');
$query->where('d.flight_id ='.$id);
$db->setQuery( $query );
$rows = $db->loadObjectList();
foreach($rows as $row) {
$rowss[] = $row->fair_type.','.$row->fair;
}
$row = implode("\n", $rowss);
return $row;
}

Duplicate value reason : your #__fairinfo table have one row and #__faredescription table have 4 rows,so that only its display duplicate value
Seems your expectation like this
4 G8-334 G8-334 2012-05-22 2012-05-22 11:10:00 13:05:00 MUMBAI (TERMINAL 1B) NEW DELHI (TERMINAL 1D) GoSmart7,566.00 INR
GoFlexi7,829.00 INR
GoBusiness9,718.00 INR
GOPROMO(ROUNDTRIP)7,136.00 INR
GoSpecial Sold out/Not
right ?

Related

how to edit opencart php codes of admin area?

i want to edit and change the admin->catalog->product->edit->option attributes name i.e. price, point and weight to something else. I do it in admin/view/template/product-form.tpl but it does not reflect the change please help.
i change this:
<td class="text-left"><?php echo $entry_subtract; ?></td>
<td class="text-right"><?php echo $entry_price; ?></td>
to this
<td class="text-left"><?php echo "something"; ?></td>
<td class="text-right"><?php echo "something"; ?></td>

How to add column to OpenCart customer list?

I use OpenCart 1.5.6.4 and 2.3
In admin panel and in customer list there is no column for Customer Id
between this place:
For Opencart 2:
You need to edit this file:
admin/view/template/customer/customer_list.tpl
1)
Find:
<td class="text-left"><?php if ($sort == 'name') { ?>
Add before it:
<td class="text-left">Customer ID</td>
2)
Find:
<td class="text-left"><?php echo $customer['name']; ?></td>
Add before it:
<td class="text-left"><?php echo $customer['customer_id']; ?></td>
For Opencart 1:
This file:
admin/view/template/sale/customer_list.tpl
1)
Find:
<td class="left"><?php if ($sort == 'name') { ?>
Add before it:
<td class="left">Customer ID</td>
2)
Find:
<td class="left"><?php echo $customer['name']; ?></td>
Add before it:
<td class="left"><?php echo $customer['customer_id']; ?></td>
For sort customers by their id for Opencart 2 in step 1 add this code:
<td class="text-left">
<?php if ($sort == 'customer_id') { ?>
Customer ID
<?php } else { ?>
Customer ID
<?php } ?>
</td>
instead of:
<td class="text-left">Customer ID</td>
Then open this file:
admin/controller/customer/customer.php
Find:
$data['sort_name'] = $this->url->link('customer/customer', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true);
Add before it:
$data['sort_customer_id'] = $this->url->link('customer/customer', 'token=' . $this->session->data['token'] . '&sort=customer_id' . $url, true);

how to add extra tab without any extension in product page in opencart

how to add extra tab without any extension in product page in opencart
may be this is the code for extra tabs any one help? regards
<div class="tabs-group"> <div id="tabs" class="htabs clearfix">Delivery
<?php if ($attribute_groups) { ?>
<?php echo $tab_attribute; ?>
<?php } ?>
<?php if ($review_status) { ?>
<?php echo $tab_review; ?>
<?php } ?>
<?php if( $productConfig['enable_product_customtab'] && isset($productConfig['product_customtab_name'][$languageID]) ) { ?>
<?php echo $productConfig['product_customtab_name'][$languageID]; ?>
<?php } ?>
</div>
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
<?php if ($attribute_groups) { ?>
<div id="tab-attribute" class="tab-content">
<table class="attribute">
<?php foreach ($attribute_groups as $attribute_group) { ?>
<thead>
<tr>
<td colspan="2"><?php echo $attribute_group['name']; ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<tr>
<td><?php echo $attribute['name']; ?></td>
<td><?php echo $attribute['text']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
</table>
</div>
<?php } ?>
may be this is the code for extra tabs any one help? regards
Add a link to div id="tabs" with a href to your custom tab's id
<div class="tabs-group">
<div id="tabs" class="htabs clearfix">
Delivery
My Tab //Your custom tab
....
Then add your tab div after
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
<div id="tab-my-tab" class="tab-content">Your html content goes here</div>

Why cart library is not working in codeigniter 3 when using MX hmvc?

Tryint to experiment the cart library, it is working ok without mx hmvc in in CI3. But as soon as i am inserting MX hmvc files (i.e MY_Loader.php and MY_Router.php in application/core folder and MX folder inside third_party folder) it is throwing error saying
Severity: Notice
Message: Undefined property: Welcome::$Session
Filename: MX/Loader.php
Line Number: 171
I am not even inside the modules just trying to use codeigniter's default controller and view.
My modified codeigniter's controller welcome.php is as below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper('form');
$this->load->helper('url');
// Load the cart library to use it.
$this->load->library('cart');
// Assuming this is the products from our database
$data['products'] = array(
array(
'id' => 'sku_888',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'xxx', 'Color' => 'White')
),
array(
'id' => 'sku_888',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'xx', 'Color' => 'green')
),
array(
'id' => 'sku_777',
'qty' => 1,
'price' => 9.95,
'name' => 'Coffee Mug'
),
array(
'id' => 'sku_666',
'qty' => 1,
'price' => 29.95,
'name' => 'Shot Glass'
)
);
// Insert the product to cart
if ($this->input->get('id') != '' && array_key_exists($this->input->get('id'), $data['products']))
{
$this->cart->insert($data['products'][$this->input->get('id')]);
}
// Lets update our cart
if ($this->input->post('update_cart'))
{
unset($_POST['update_cart']);
$contents = $this->input->post();
foreach ($contents as $content)
{
$info = array(
'rowid' => $content['rowid'],
'qty' => $content['qty']
);
$this->cart->update($info);
}
}
$this->load->view('welcome_message', $data);
}
}
and the default codeigniter view welcome_message.php, i modified as below
<b>Products</b>
<table width="100%" border="1">
<tr>
<td width="37%">ID</td>
<td width="30%">Name</td>
<td width="16%">Price</td>
<td width="16%"> </td>
</tr>
<?php $product_array_index = 0;?>
<?php foreach($products as $product):?>
<tr>
<td><?php echo $product['id'];?></td>
<td>
<?php
echo $product['name'] ;
if (array_key_exists('options', $product)) {
echo '<hr>';
foreach ($product['options'] as $key => $value)
{
echo '<strong>' . $key . '</strong> : '. $value . '<br/>';
}
}
?>
</td>
<td><?php echo $product['price'];?></td>
<td>Add to Cart</td>
</tr>
<?php $product_array_index ++;?>
<?php endforeach;?>
</table>
<hr>
<b>Your Cart</b>
<?php echo form_open(base_url()); ?>
<table cellpadding="6" cellspacing="1" style="width:100%" border="1">
<tr>
<th>QTY</th>
<th>Item Description</th>
<th style="text-align:right">Item Price</th>
<th style="text-align:right">Sub-Total</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td><?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
<?php endforeach; ?>
</p>
<?php endif; ?>
</td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
<td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"></td>
<td class="right"><strong>Total</strong></td>
<td class="right" align="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('update_cart', 'Update your Cart'); ?></p>
How to make it work?

Adding custom field to OpenCart admin with VQmod

Trying to add a short description field to the category pages in OpenCart back office. Have multiple instances of VQmod XML working fine in controllers and models but trying to use the below to add the field to the category page appears to be doing nothing at all. Nothing gets added/replaced at all in the category_form.tpl.
<!-- This adds the short description field to the admin category page -->
<file name="admin/view/template/catalog/category_form.tpl">
<operation>
<search position="replace"><![CDATA[ <tr>
<td><?php echo $entry_description; ?></td>
<td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
</tr>]]></search>
<add><![CDATA[ <tr>
<td><?php echo $entry_short_description; ?></td>
<td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
</tr>
<tr>
<td><?php echo $entry_description; ?></td>
<td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
</tr>]]></add>
</operation>
</file>
There is clearly a better approach to this as I don't think I should be trying to replace all this code here but if I anyone could kindly check that code over and point out where I've gone wrong, that would be great. Thanks.
Update
My XML code is wrapped in <modification> </modification> by the way....
I have tried using offset and referred to the VQmod documentation but still am unable to get this right...
I have tried:-
<file name="admin/view/template/catalog/category_form.tpl">
<operation>
<search position="replace" offset="1"><![CDATA[<td><?php echo $entry_description; ?></td>]]></search>
<add><![CDATA[ <tr>
<td><?php echo $entry_short_description; ?></td>
<td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
</tr>
<tr>
<td><?php echo $entry_description; ?></td>
<td><textarea name="category_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($category_description[$language['language_id']]) ? $category_description[$language['language_id']]['description'] : ''; ?></textarea></td>
</tr>]]></add>
</operation>
</file>
First whole code should be wrapped in
<modification>
<file ...>
....
</file>
</modification>
Second you can't search multiple lines you can search particular line and then use offset attribute
for your case use
<search position="replace" offset="1"><![CDATA[ <td><?php echo $entry_description; ?></td>]]></search>
refer to vQmod documentation.