php 有人告诉我结果未显示?[duplicate]

ca1c2owp  于 2022-12-10  发布在  PHP
关注(0)|答案(1)|浏览(138)

此问题在此处已有答案

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP(29个答案)
20小时前关闭。

<?php 

$stmt=DB_uf::prepare('SELECT c_id, c_name   FROM cata_log ORDER BY c_id, c_name') ;
  
     $stmt->execute();
    
  $result = $stmt->fetchall(PDO::FETCH_NUM);  
    foreach ($result as $key => $row) {
    $catalog = $row[':c_id'];
    $product_name = $row[':c_name'];
    echo $catalog ;
    echo $product_name;
   }
  
//if ($result->num_rows > 0) {}
//$stmt->execute();
?>

结果查找为
警告:第19行的C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_id”
警告:第20行C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_name”
警告:第19行的C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_id”
我如何从好心帮助我中得到回报?只有这个程序改进了

<?php 

$stmt=DB_uf::prepare('SELECT c_id, c_name   FROM cata_log ORDER BY c_id, c_name') ;
  
     $stmt->execute();
    
  $result = $stmt->fetchall(PDO::FETCH_NUM);  
    foreach ($result as $key => $row) {
    $catalog = $row[':c_id'];
    $product_name = $row[':c_name'];
    echo $catalog ;
    echo $product_name;
   }
  
//if ($result->num_rows > 0) {}
//$stmt->execute();
?>

警告:第19行的C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_id”
警告:第20行C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_name”
警告:第19行的C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_id”
警告:第20行C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_name”
警告:第19行的C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_id”
警告:第20行C:\xampp\htdocs\project\menu_selector. php中未定义的数组键“:c_name”

nkhmeac6

nkhmeac61#

删除:在数组中Keys
也就是说

<?php 

$stmt=DB_uf::prepare('SELECT c_id, c_name   FROM cata_log ORDER BY c_id, c_name') ;
  
     $stmt->execute();
    
  $result = $stmt->fetchall(PDO::FETCH_NUM);  
    foreach ($result as $key => $row) {
    $catalog = $row['c_id'];
    $product_name = $row['c_name'];
    echo $catalog ;
    echo $product_name;
   }
  
//if ($result->num_rows > 0) {}
//$stmt->execute();
?>

相关问题