This is a code am using. However facing an issue due to common id field in all tables
Problem vid='.$row->id.'
- in url
The id field in the url is showing from #__usedcar_products
table, while i want that id should be picked from #__usedcar_variants
table
See Url in End of full code
<a href="index.php?option=com_usedcar&view=product&pid='.$row->v_prod_id.'&vid='.$row->id.'">
Below is Full Code
function loadMainCat($brand,$Carmodel,$minprice,$maxprice,$reg_year, $reg_city, $kms_min,$kms_max,$location){
$mainframe =JFactory::getApplication();
$option = JRequest::getCmd('option');
$database =JFactory::getDBO();
global $Itemid;
/////////////My Sql Condition Start//////////////
$cond="";
if($brand){ $cond.=" and cc.id= ".$brand."";}
if($Carmodel){ $cond.=" and cv.v_prod_id= ".$Carmodel."";}
if($minprice!="" and $maxprice!=""){
$cond.=" and (cv.v_price between ".$minprice." and ".$maxprice.")";
}elseif($minprice){ $cond.=" and cv.v_price >= ".$minprice."";
}elseif($maxprice){ $cond.=" and v_price <= ".$maxprice."";}
if($reg_year){ $cond.=" and cv.registration_year =".$reg_year."";}
if($reg_city){ $cond.=" and cv.registration_city ='".$reg_city."'";}
if($kms_min!="" and $kms_max!=""){ $cond.=" and (cv.kms_run between ".$kms_min." and ".$kms_max.")";
}elseif($kms_min){ $cond.=" and cv.kms_run >= ".$kms_min."";
}elseif($kms_max){ $cond.=" and cv.kms_run <= ".$kms_max."";}
if($location){ $cond.=" and cv.v_location='".$location."'";}
/////////////My Sql Condition End//////////////
//////////Paging////
jimport('joomla.html.pagination');
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limit = 2;
$limitstart = $mainframe->getUserStateFromRequest( 'limitstart', 'limitstart', 0, 'int' );
$sql = "select * from #__usedcar_variants cv inner join #__usedcar_products cp inner join #__usedcar_categories cc on cc.id=cp.prod_cat_id and cp.id=cv.v_prod_id and cv.id=cv.id and cv.state='1' where 1 $cond order by cv.id desc";
$database->setQuery($sql);
$total = $database->loadResult();
$pageNav = new JPagination( $total, $limitstart, $limit );
$database->setQuery( $sql, $this->getState('limitstart'), $this->getState('limit') );
$database->getQuery($sql);
$rows = $database->loadObjectList();
$list="";
$flg=0;
if($rows){
$list.=' <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<!--listing start header-->
</td>
</tr>';
foreach($rows as $row){
if($row->v_small_img!=""){
$img = "/".$row->v_small_img;
}else
$img ='#';
$list.='<tr>
<td>
<div class="technology">'.$row->cat_name.'</div>
<p><a href="index.php?option=com_usedcar&view=product&pid='.$row->v_prod_id.'&vid='.$row->id.'"><b>Used</b></a></p>
<p><a href="index.php?option=com_usedcar&view=product&pid='.$row->v_prod_id.'&vid='.$row->id.'"><b>Used</b></a></p>