emma57573 Posted November 19, 2008 Share Posted November 19, 2008 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 More sharing options...
Mark Baker Posted November 19, 2008 Share Posted November 19, 2008 Retrieve all your prices into an array in the while loop, then sort the array. Link to comment https://forums.phpfreaks.com/topic/133330-solved-selecting-highest-mysql-value/#findComment-693408 Share on other sites More sharing options...
Mchl Posted November 19, 2008 Share Posted November 19, 2008 One possible solution: SELECT price FROM my_table WHERE ... ORDER BY price DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/133330-solved-selecting-highest-mysql-value/#findComment-693410 Share on other sites More sharing options...
emma57573 Posted November 19, 2008 Author Share Posted November 19, 2008 I will give that a go and let you know how I get on thanks Link to comment https://forums.phpfreaks.com/topic/133330-solved-selecting-highest-mysql-value/#findComment-693412 Share on other sites More sharing options...
emma57573 Posted November 19, 2008 Author Share Posted November 19, 2008 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 Link to comment https://forums.phpfreaks.com/topic/133330-solved-selecting-highest-mysql-value/#findComment-693431 Share on other sites More sharing options...
emma57573 Posted November 19, 2008 Author Share Posted November 19, 2008 Ignore me, Ive been working on this script to long today. It was a users error $buy_price instead of $buyprice !!!! Its working now thanks I would be lost without this place Link to comment https://forums.phpfreaks.com/topic/133330-solved-selecting-highest-mysql-value/#findComment-693444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.