Asheeown Posted January 11, 2007 Share Posted January 11, 2007 I've been digging through manuals, the internet, and I still can't find something in PHP or mysql to find the least of numbers that are being called from a databaseDoes anyone know a function to do this? Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/ Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 So what i'm basically being told by the dead silence is their is no way? Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158582 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Your question is pretty vague, do you mean...[code]SELECT MIN(fld) FROM tbl;[/code]? Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158586 Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 exactly what I mean't thank you Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158615 Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 Wait thats my bad it's not exactly what i'm looking for.I have a table and each entry into that table has 12 different columns of numbers, which represent prices of a company, I want to find the minimum number of each entry for those 12 columns. Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158631 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 That wreaks of poor database design but ah well.You need to run a query which retrieves all these values into an array, then sort it. eg;[code]<?php // connect $sql = "SELECT p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 FROM tbl WHERE companyid = 4;"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result) > 0)) { $row = mysql_fetch_array($result); sort($row); echo $row[0]; } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158661 Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 I just used the least function for mysql, but another question the least number that it found...is their a way to get that column name[code=php:0]$InterQuery = mysql_query("SELECT least(inter1,inter2,inter3,inter4,inter5,inter6,inter7,inter8,inter9,inter10,inter11,inter12) FROM compare_npanxxcost") or die(mysql_error());[/code]Showing what column it got the least number out ofFor example if "inter3" had the lowest number there, how could you tell that it was in fact "inter3"? Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158662 Share on other sites More sharing options...
Draicone Posted January 11, 2007 Share Posted January 11, 2007 Well, no, because the problem is that it is selecting the least of all those columns. You need a query for each. I suppose you can use a for loop in php to automate the process. Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158699 Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 Somewhere, someplace it has to show where that number came from. Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158705 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 Use mysql_fetch_assoc instead of mysql_fetch_array Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158711 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Why do you need it?[url=http://php.net/array_keys]array_keys[/url] could get it if used with [url=http://php.net/mysql_fetch_assoc]mysql_fetch_assoc[/url](). Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158712 Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 Its a company price, they aren't the same for each entry thought so in order to track them just take the column name "inter3" and use another mysql table to tell what it is and inter3 matches with a company name Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158718 Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Author Share Posted January 11, 2007 I don't really see how I could use array_keys could you elaborate a little please? Quote Link to comment https://forums.phpfreaks.com/topic/33807-least/#findComment-158735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.