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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?