How do I find the longest value in my mysql table?
So you probably know that the LENGTH() function applied to a fieldname will return the length of that field.
So then all you need is the relevant query to find the length of the longest item in a field like so:
<?php
$q = mysql_query("SELECT LENGTH(firstname) AS thelength FROM myfriends ORDER BY thelength DESC LIMIT 1");
$longestname = mysql_result($q,0,0);
echo "The longest first name is $longestname letters long!";
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More mysql PHP Questions
How do i list a record in front that is recently added to the table?How do I access the current time with mysql?
What is the correct way to connect to a MySQL database?
the uploading status shows success but not showing in the server is empty the written php file is first gave warning cannot uploaded warning in foreach loop but i corrected mistake by keeping above if condition and no error status shows success upload b
What is difference between mysql_fetch_array and mysql_fetch_object?
