Jump to content

I need to only show my lowest price on my external front page


thehost5968

Recommended Posts

Hi

 

I need to show my lowest price on my external front page I have this to get all the info I need from the Database:

 

$query = "
Select
   tblproducts.`id`,
   tblproducts.`type`,
   tblproducts.`gid`,
   tblproducts.`name`,
   tblproducts.`description`,
   tblproducts.`hidden`,
   tblproducts.`showdomainoptions`,
   tblproducts.`welcomeemail`,
   tblproducts.`stockcontrol`,
   tblproducts.`qty`,
   tblproducts.`proratabilling`,
   tblproducts.`proratadate`,
   tblproducts.`proratachargenextmonth`,
   tblproducts.`paytype`,
   tblproducts.`subdomain`,
   tblproducts.`autosetup`,
   tblproducts.`servertype`,
   tblproducts.`defaultserver`,
   tblproducts.`configoption1`,
   tblproducts.`configoption2`,
   tblproducts.`configoption3`,
   tblproducts.`configoption4`,
   tblproducts.`configoption5`,
   tblproducts.`configoption6`,
   tblproducts.`configoption7`,
   tblproducts.`configoption8`,
   tblproducts.`configoption9`,
   tblproducts.`configoption10`,
   tblproducts.`configoption11`,
   tblproducts.`configoption12`,
   tblproducts.`configoption13`,
   tblproducts.`configoption14`,
   tblproducts.`configoption15`,
   tblproducts.`configoption16`,
   tblproducts.`configoption17`,
   tblproducts.`configoption18`,
   tblproducts.`configoption19`,
   tblproducts.`configoption20`,
   tblproducts.`configoption21`,
   tblproducts.`configoption22`,
   tblproducts.`configoption23`,
   tblproducts.`configoption24`,
   tblproducts.`freedomain`,
   tblproducts.`freedomainpaymentterms`,
   tblproducts.`freedomaintlds`,
   tblproducts.`upgradepackages`,
   tblproducts.`configoptionsupgrade`,
   tblproducts.`billingcycleupgrade`,
   tblproducts.`tax`,
   tblproducts.`affiliateonetime`,
   tblproducts.`affiliatepaytype`,
   tblproducts.`affiliatepayamount`,
   tblproducts.`downloads`,
   tblproducts.`order`,
   tblproductgroups.`id`,
   tblproductgroups.`name` As `groups name`,
   tblproductgroups.`disabledgateways`,
   tblproductgroups.`hidden`,
   tblproductgroups.`order`,
   tblpricing.`id`,
   tblpricing.`type`,
   tblpricing.`currency`,
   tblpricing.`relid`,
   tblpricing.`msetupfee`,
   tblpricing.`qsetupfee`,
   tblpricing.`ssetupfee`,
   tblpricing.`asetupfee`,
   tblpricing.`bsetupfee`,
   tblpricing.`monthly`,
   tblpricing.`quarterly`,
   tblpricing.`semiannually`,
   tblpricing.`annually`,
   tblpricing.`biennially`
From
(tblproducts tblproducts LEFT OUTER JOIN tblproductgroups tblproductgroups ON (tblproducts.gid = tblproductgroups.id)) LEFT OUTER JOIN tblpricing tblpricing ON (tblpricing.relid = tblproducts.id)
Where 
    ( tblproductgroups.hidden <> 'on' ) 
   And ( tblpricing.`currency` = 1 ) 
   And ( tblpricing.type = 'product' )
Order by
   tblproductgroups.id Asc
" ;

 

 

but the only way I can code to get the prices is :

   $mygpricemonthly = mysql_result($result,$i,'monthly');
   $mygpricequarterly = mysql_result($result,$i,'quarterly');
   $mygpricesemiannually = mysql_result($result,$i,'semiannually');
   $mygpriceannually = mysql_result($result,$i,'annually');
   $mygpricebiennially = mysql_result($result,$i,'biennially');

 

I have got it to sort to give me the lowest price:

 

$numbers = array($mygpricemonthly,$mygpricequarterly,$mygpricesemiannually,$mygpriceannually,$mygpricebiennially);
   sort($numbers);
   for ($i=0; $i <= 2; $i++) 
   $numbers[$i]."<br \>";

   echo "The lowest value is: <br>";
   echo $numbers[0]

 

but how would I get the lowest price if it = more then 0.00.

 

Can some one help me with is?

Link to comment
Share on other sites

  • 1 month later...

I'm sorry I'm not able to help as I found this when wanting to do the exact thing myself plus allow the user to change the currency to see the price in that other one.

 

Did you find a solution? I would be very grateful to see how to do it.

 

Cheers,

 

Henrik

Link to comment
Share on other sites

Write a recursive function that does this:

 

1) look at $number[0]. Is it > 0? If so, stop.

2) If not, look at $number[0+1], etc...

 

so:

 

// populate the array
$numbers = array($mygpricemonthly,$mygpricequarterly,$mygpricesemiannually,$mygpriceannually,$mygpricebiennially);

// sort from lowest to highest
sort($numbers);

// call our recursive function
$lowest = lowestnum($nums, $num);

// echo the result
if ($lowest["index"] == -1)
echo "There was no lowest value above zero.<br />";

else
echo "The lowest value was found at index [" . $lowest["index"] . "] and is: " . $lowest["value"] . "<br />";

// recursive function    
function lowestnum($nums, $num) {

// result array
$result = array();

// if the number is greater than zero, stop.
if ($nums[$num] > 0) {

	$result["index"] = $num;
	$result["value"] = $nums[$num];
	return $result;

}

// if $num+1 would be out of bounds, stop.
// if not, call our recurisve function with $num+1
if (($num+1) >= count($nums)) {
	$result["index"] = -1;
	return $result;
}

else
	lowestnum($nums, $num+1);

}

Link to comment
Share on other sites

  • 1 year later...

Your lowest priced item will be your lowest prices package in the monthly value.

 

SELECT a.monthly FROM tblpricing a

 

JOIN tbproducts b ON a.relid = b.ia

 

WHERE b.id = 'a product id'

 

AND a.type = 'product'

 

AND a.monthly > '0' ORDER BY a.monlthly ASC

 

 

 

If you want to return the very lowest from price because you discount higher term packages, you need to do this

// if triennial is the highest product term you use otherwise select the highest

$select  ="SELECT a.triennial, b.name FROM tblpricing a JOIN tbproducts b ON a.relid = b.id WHERE b.id = 'a product id' AND a.type = 'product' ORDER BY a.triennial ASC";
// set our array
$lowest_prices = Array();

$query = mysql_query($sql);
while($fetch = mysql_fetch_assoc($query){

          // lets play mathematician
         // take out value divide it by months in the term and round down to two decimal places.
         $low_price = round(($fetch['triennial']  / 36), 2);

          $lowest_price[] = $lowprice;
}

 

You should now have an array with ascending prices (low to high) that you can access as follows

$smarty->assign('lowest_prices', $lowest_prices);

 

where i is out product order in the template {$lowest_prices[$i]}

 

 

Thats a crude example. you will ofcourse want to come up with a new associative array probable containing least a product id so an array update will need to take place within the while with the lowest price before assigning to the $lowest_price[] array

Edited by disgruntled
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated