Name
mysql_fetch_lengths()
Synopsis
array mysql_fetch_lengths(results)This function returns an array containing the length of each field of a results set from a MySQL query. Here is an example:
...
$sql_stmnt = "SELECT wr_id, description, instructions
FROM workreq";
$results = mysql_query($sql_stmnt);
while($row = mysql_fetch_object($results)) {
$length = mysql_fetch_lengths($results);
print "$row->wr_id: description: $length[1],
instructions: $length[2] \n";
}
...In this example, each work request number is selected, along
with the brief description and the lengthy instructions. Looping
through each row that is retrieved as an object with
mysql_fetch_object() and a
while statement, the code determines the length of
the data for all three fields with
mysql_fetch_lengths() and places them in an
array. Within the statement block of the while
statement, the value of the wr_id field is
extracted, and the lengths of the description field
and the instructions field are pulled out of the
$length array using the relative index number for
each. Here are a few lines of output from this script:
... 5753: description: 26, instructions: 254 5754: description: 25, instructions: 156 5755: description: 25, instructions: 170
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access