Php 字符总数(长度)

Php 字符总数(长度),php,Php,我需要显示标题字符总数。 $totals只返回0,哪里有错 有什么建议吗 $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_q

我需要显示标题字符总数。 $totals只返回0,哪里有错

有什么建议吗

    $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;

请尝试/使用此功能,至少使用
mysqli
。测试了它,它的工作

$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/>';

        }
}

$conn->close();
$servername=“localhost”;
$username=“您的用户名”;
$password=“您的密码”;
$dbname=“您的\u db\u名称”;
$conn=newmysqli($servername、$username、$password、$dbname);
如果($conn->connect\u错误){
die(“连接失败:”.$conn->connect\U错误);
} 
$sql=“选择长度(标题)作为标题\数量、订单标题”;
$res\u characters\u qty=mysqli\u查询($conn,$sql);
如果(mysqli\u num\u行($res\u字符数)>0){
而($row=mysqli\u fetch\u assoc($res\u characters\u qty)){
echo$row['title_quantity'].
; } } $conn->close();
请尝试/使用此功能,至少使用
mysqli
。测试了它,它的工作

$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/>';

        }
}

$conn->close();
$servername=“localhost”;
$username=“您的用户名”;
$password=“您的密码”;
$dbname=“您的\u db\u名称”;
$conn=newmysqli($servername、$username、$password、$dbname);
如果($conn->connect\u错误){
die(“连接失败:”.$conn->connect\U错误);
} 
$sql=“选择长度(标题)作为标题\数量、订单标题”;
$res\u characters\u qty=mysqli\u查询($conn,$sql);
如果(mysqli\u num\u行($res\u字符数)>0){
而($row=mysqli\u fetch\u assoc($res\u characters\u qty)){
echo$row['title_quantity'].
; } } $conn->close();
哎哟,那是旧的
mysql
扩展吗?是的,它是旧的mysql扩展:-)也许第一行的那列是空的。您的意思是只检查第一行吗?例如,如果您在phpmyadmin中运行查询,它是否会返回一些内容?因为我已经试过了,并且得到了正确的返回结果,我有418行,第415行有12个字符,就像mysql在运行select directlyOuch时说的那样,这是旧的
mysql
扩展,对吗?是的,它是旧的mysql扩展:-)也许第一行的列是空的。您的意思是只检查第一行吗?例如,如果您在phpmyadmin中运行查询,它是否会返回一些内容?因为我已经试过了,并且得到了正确的返回结果,所以我有418行,第415行有12个字符,就像mysql直接运行select时说的那样