Hid Dencum Hid Dencum - 1 year ago 58
PHP Question

Total numbers of characters (LENGTH)

I need to show a total of title characters.
$totals only return 0, where do I wrong?

Any suggestion?

$characters_qty = mysql_query("
SELECT LENGTH(title) AS title_quantity, title FROM orders

$res_characters_qty = mysql_fetch_assoc($characters_qty);
$totals = $res_characters_qty ['title_quantity'];
echo $totals;

Answer Source

Please try/use this which at least using mysqli. Tested it and it's work.

$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_db_name";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

    $sql = "SELECT LENGTH(title) AS title_quantity, title FROM orders";
    $res_characters_qty  = mysqli_query($conn, $sql);
    if (mysqli_num_rows($res_characters_qty ) > 0) {
        while($row = mysqli_fetch_assoc($res_characters_qty )) {
            echo $row['title_quantity']. '<br/>';


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download