duanpuqi9965 2014-03-27 18:47
浏览 12
已采纳

只返回每行值的第一个字母

I'm having a bit of an issue with what is normally a simple foreach loop through a query array. I am trying to target individual field values from a row, but its only returning the first letter of each. New to OCI so any help would be appreciated.

$custcart = oci_parse($conn,"SELECT * FROM A113222813_CARTLINE WHERE CUST_ID=  
:cust_id");
oci_bind_by_name($custcart, ":cust_id", $_SESSION["CUST_ID"]);

if (!$custcart) {
    echo "There was an error. Please wait wwhile we redirect you.";
    $url ="login.php";
    $time_out = 5;
    header("refresh: $time_out; url=$url");
}

oci_execute($custcart);
include 'includes/header.php';

while ($row = oci_fetch_array($custcart, OCI_ASSOC)) {
    foreach ($row as $item) {
        echo $item['CART_NAME'];

    }
}
  • 写回答

1条回答 默认 最新

  • duanmei9980 2014-03-27 18:52
    关注

    The while is looping over all returned rows. You are then foreach ing across that row and accessing the columns in the row (don't do that). You just want the while and access CART_NAME in $row:

    while ($row = oci_fetch_array($custcart, OCI_ASSOC)) {
        echo $row['CART_NAME'];
    }
    

    If you want to store the rows in an array to use more than once in the script, then:

    while ($row[] = oci_fetch_array($custcart, OCI_ASSOC)) { }
    
    //now or later
    
    foreach ($row as $item) {
        echo $item['CART_NAME'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类