0

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

3
  • Stop use deprecated functions! Commented Sep 29, 2015 at 12:18
  • $att["name"]; this line doesn't do anything. did you mean to echo? Commented Sep 29, 2015 at 12:19
  • check my update - this is how i have it. i had been testing and forgot to add it back in Commented Sep 29, 2015 at 12:20

1 Answer 1

4

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.