duanque19820925 2012-08-30 08:33 采纳率: 0%
浏览 36

PHP:如何从返回数组的函数中读取值

So I have form:

    <form method="post">
    Name: <input type="text" name="name" value<? if(isset($_GET['edit'])) {echo '="'. person($_GET['edit']) .'"';} ?>/><br>
    Surname: <input type="text" name="surname" value<? if(isset($_GET['edit'])) {echo '="'. person($_GET['edit']) .'"';} ?>/><br>       
    Age: <input type="text" name="age" value<? if(isset($_GET['edit'])) {echo '="'. person($_GET['edit']) .'"';} ?>/><br>
    <input type="submit" value="Submit" name="submit"/> 
</form>

and

    function person($id) {
    $query = 'SELECT name, sname, age FROM persons WHERE ID='.$id.';';
    $result = mysql_query($query);
    return $row = mysql_fetch_row($result);
}

So Function returns an array, How can I get from this function to display me only: 'name' / 'sname' / 'age' in each of input value

  • 写回答

4条回答 默认 最新

  • doubi8965 2012-08-30 08:36
    关注

    It's just like a normal array, so you can use [id]. If you use mysql_fetch_row it must be numbers from 0 to n-1 where n is number of items in array in order that you did in query. If you have mysql_fetch_assoc you can use $test['name'], $test['sname'], $test['age'].

    $test = person(5);
    
    echo $test[0].$test[1].$test[2]; //will show name|sname|age (withouth '|').
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接