download2565 2014-03-31 09:13
浏览 74
已采纳

PHP - 注意:未定义的偏移量:0英寸

I'm having troubles using arrays. I don't know why, but my menu can't read my arrays...

I always receive this notice: PHP - Notice: Undefined offset: 0

function DB_array($query,$return_type){
    connect();
    $q = mysql_query($query);


    switch ($return_type){

        case 'a+':
            $num_fields = mysql_num_fields($q); 
            $j=0;
            $x = 0;
            $val = array();
            while($row = mysql_fetch_array($q)){  
                for ($j=0; $j < $num_fields; $j++){
                    $name = mysql_field_name($q, $j);
                    $val[$x][$name] = $row[$name];
                }
                $x++;
            }
            break;

Menu code

<?php

 /*Return Type - Symbology
 *      //SELECT
 *      a+ | Data to array
 */

include(PATH_ROOT . '/modules/menu/view/menu_view.php');
function menuModel(){
        $query = ("SELECT * FROM menu WHERE back = 1");
        $val = DB_array($query,'a+');
        $name = $val['0']['friendlyname'];
        $url = $val['0']['url'];
        menu($url,$name);
}
?>
  • 写回答

2条回答 默认 最新

  • donglvhe7591 2014-03-31 09:14
    关注

    you are accessing array key as a string when it's an integer since you set it this way:

    $val[$x][$name] assuming that your x is $x = 0;

    try this instead:

    $name = $val[0]['friendlyname'];
    $url = $val[0]['url'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 带序列特征的多输出预测模型
  • ¥15 VB.NET读取电脑主板序列号
  • ¥15 Python 如何安装 distutils模块
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?
  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)
  • ¥30 comfyui openpose报错
  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错