Jump to content

[SOLVED] Selecting highest MYSQL value


emma57573

Recommended Posts

If having some issues figuring this out. I have a loop that shows all the items purchased for said '$userid'  Which is working great! It pulls out all the details ie: qty, price, shipping.

I want to identify a value in the loop as the highest value in the loop and Im not quite sure how to go about it:

 

$userid=1;
$seller_id=2;

$rquery="select * from my_table where buyer_user_id=$userid and seller_user_id=$seller_id";
$ssql=mysql_query($rquery);
$sst=mysql_fetch_array($ssql);


  $tnt=0;
while($sst){

$PRICE=mysql_fetch_array(mysql_query("select * FROM my_table WHERE buyer_user_id=$userid and seller_user_id=".$sst["seller_user_id"]));	

//I WANT TO FIND THE HIGHEST 'price' IN $PRICE AND...

$highest_price=ENTER THE HIGHEST PRICE HERE;


if (($sst["quantity"]==1)&&(array_key_exists($sst["seller_user_id"], $sst)&&(IF $sst["price"]==$highest_price))){


echo $sst["price"];


				  
				  }

$sst=mysql_fetch_array($ssql);
        			  $tnt++;            
				}// end while

 

Im just stuck on the syntax to find the highest price from $PRICE - Please ignore and other syntax errors I rewrote this for the sake of example so their may be other errors but please ignore them its just this highest price thing Im stuck on.

 

 

Many Thanks

 

Emma

Link to comment
https://forums.phpfreaks.com/topic/133330-solved-selecting-highest-mysql-value/
Share on other sites

Thank you that kind of works as when I echo it gives me the answer im looking for but Im not sure now why the following wont work

				
if ($sst["price"]==$PRICE["price"]){

do what I need to do
}

It just ignores the if statement.

could this have anything to do with the answers being in decimals?

 

The $sst["price"] and $PRICE["price"] are both 0.10

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.