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条)

相关推荐 更多相似问题