2015-09-29 143 views
0

我創建通過記錄循環的功能,我想回項目陣列PHP返回數組

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; 
    } 
} 

我在這裏稱之爲:

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

但這呼應h5而名= 55388-20150929124302-screen dump 28092015.docx

+0

停止使用不推薦使用的函數! – rray

+0

'$ att [「name」];'這行不做任何事。你的意思是「回聲」? – FuzzyTree

+0

檢查我的更新 - 這是我的方式。我一直在測試,並忘記將其添加回 – charlie

回答

4

我認爲你需要的陣列組合

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; 
    } 
} 
+0

完美 - 謝謝 – charlie