PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I find the longest value in my mysql table?


Often what you need to do is work out which function will get you closest to what you want to achieve, and then combine this with your knowledge of manipulating queries to get exactly what you want.

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!"
?>



ASK A QUESTION

More mysql PHP Questions

What is difference between mysql_fetch_array and mysql_fetch_object?

Why does this code not work? Returns this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND ClaimNo = AND UserName = john' at line 2

I tried to do query,but it didnt work i receive an error message arning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in

how will use a mysql_query to get a single4 person list? With example.

Welcome by regersteration form First name: last name:



Custom Search