dprlv04662 2015-09-29 12:12
浏览 50
已采纳

PHP在循环内返回数组

i am creating a function that loops through records and i want to return the array of items

if(!function_exists("TicketAttachments")) {
    function TicketAttachments($update_sequence) {
        global $conn, $pdo_conn;

        $results = array();
        $sql="SELECT * from ticket_updates where ticketnumber = '".$update_sequence."' and type = 'attachment' ";
        $rs=mysql_query($sql,$conn);
        while($result=mysql_fetch_array($rs)) {
            $results["link"] = 'media/ticket_attachments/'.$result["notes"];
            $results["name"] = $result["notes"];
        }

        return $results;
    }
}

i am calling it here:

$attachments = TicketAttachments($TicketUpdate["sequence"]);
foreach($attachments as $att) {
    echo $att["name"];
}

but this is echoing h5 whereas name = 55388-20150929124302-screen dump 28092015.docx

  • 写回答

1条回答 默认 最新

  • dongyi7669 2015-09-29 12:21
    关注

    I think you need to combine the array

    if(!function_exists("TicketAttachments")) {
        function TicketAttachments($update_sequence) {
            global $conn, $pdo_conn;
    
            $results = array();
            $sql="SELECT * from ticket_updates where ticketnumber = '".$update_sequence."' and type = 'attachment' ";
            $rs=mysql_query($sql,$conn);
            while($result=mysql_fetch_array($rs)) {
                $results[] = array(
                    "link"=>'media/ticket_attachments/'.$result["notes"],
                    "name" => $result["notes"];
                );
            }
            return $results;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入