Return the field length in the result set:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT name,url FROM websites ORDER BY alexa";if ($result=mysqli_query($con,$sql)){ $row=mysqli_fetch_row($result); // Display field length foreach (mysqli_fetch_lengths($result) as $i=>$val) { printf("The length of field %2d is: %2d",$i+1,$val); echo "<br>"; } // Release the result set mysqli_free_result($result);}mysqli_close($con);?>
The mysqli_fetch_lengths() function returns the field lengths in the result set.
mysqli_fetch_lengths( result ) ;
parameter | describe |
---|---|
result | Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result(). |
Return value: | Returns an array if the integer represents the length of each field (column), or FALSE if an error occurs. |
---|---|
PHP version: | 5+ |