douxi3085 2012-03-22 00:15
浏览 16
已采纳

显示数组的值

I'm trying to get a specific value from a mysql_fletch_assoc array. I explain. Here is the database. Table: config with 2 fields: setting and value.

SETTING | VALUE
width | 100    
height | 50

And this is the query:

$result = (mysql_query("SELECT setting, value FROM config"));
while($setting = mysql_Fetch_assoc($result)){


    echo $setting['value'];
    echo "<br>";

Now i can see the entire array. I want to display every element individually. I tryed with $setting['value']['0'], $setting['value']['width'] with no success.

Edit: basically i want to do something like this:

echo $setting['value']['width'] gives -> 100 
echo $setting['value']['height'] gives -> 50

I hope that now it's more clear

  • 写回答

5条回答 默认 最新

  • duande9301 2012-03-22 00:36
    关注

    First, may be there is a typo error mysql_Fetch_assoc, fix this to mysql_fetch_assoc.

    And In order to receive the values on your pattern, do the following

    $setting = array();
    while($row = mysql_fetch_assoc($result)) {
         $setting['value'][$row['setting']] = $row['value'];
    }
    

    Now, you can implement them as you want

    echo $setting['value']['width']; // will give -> 100 
    echo $setting['value']['height']; // will give -> 50
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题