doumeng1143 2017-07-20 01:05
浏览 101

为什么mysqli_fetch_all()不能与一个结果行一起使用?

I'm confused about the results I get from using mysqli_fetch_all() and mysqli_fetch_array.

I wrote a function to grab arrays from the primary key table that match the foreign key of another table where $field is the desired field in the primary key table and $property in the FK table.

function getProp($table,$field,$property,$cnn){
    $findRow = "SELECT * FROM $table WHERE $field='$property'";
    $res = mysqli_query($cnn,$findRow);
    if ($res) {
        $row = mysqli_fetch_array($res,MYSQLI_ASSOC);
        return $row;    
    } else {
        echo "we couldn't find the row that matched $field";
    }
}

Now the idea is that there should be only one match found in the primary key table. So I thought replacing mysql_fetch_array() with mysqli_fetch_all() would be okay. However, when I invoke the function like so:

$profileRow = getProp('profile','id', $runner_id, $cnn);
$profileRow['question_text'];
$profileRow['avatar']`

I get the following error:

Undefined index: avatar

I would appreciate any help. I looked at the PHP manual, but don't understand why these MySQL actions yield different results in my case.

EDIT--

Thanks for your help, but I was specifically asking about what caused the error. Please explain to me as if I were a six year old - most technical explanations pass over my head. For example what does this mean?:

mysqli_fetch_all() should only be used in those situations where the fetched result set will be sent to another layer for processing.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab