I’m quite new in PHP dev and I can’t find a way to solve my problem.
I have to clean a some data in my Mysql database. I have a date column in my DB full of time periods like
-520;-510;0;-500;-530;-599;-499;-510;-490;-500;0;-450
and I want to extract the min and max value from it, so that I will only have 2 time period left.
I tried this :
$sql = "SELECT date FROM records WHERE serial = 1";
$requete = mysql_query($sql,$cnx) or die(".mysql_error().");
while($result = mysql_fetch_array($requete))
{
$res = $result[date];
$min = min($res);
$max = max($res);
}
I understand that it can’t work because min and max functions are only working with an array but I don’t know how to tranform my $result[date] in an new array.
assuming that the DB “date” field contains a string of numbers seperated by ; like you described then you can use the explode() function to turn that string into an array and then use max() and min() on that array
if it s a one number per row then do it with SQL like described in the other answer