lional Posted September 9, 2008 Share Posted September 9, 2008 Hi I have the following format in a mysql table Ref No File 27 file1.jpg 27 file2.jpg 27 file3.jpg 27 file4.jpg 27 file5.jpg I need to create an array for all ref_no 27 and the array must look like this $files = array("file1.jpg","file2.jpg","file3.jpg","file4.jpg","file5.jpg"); How is this possible Link to comment https://forums.phpfreaks.com/topic/123413-pulling-array-from-mysql-table/ Share on other sites More sharing options...
Minase Posted September 9, 2008 Share Posted September 9, 2008 while ($query = mysql_fetch_array(mysql_query("SELECT * FROM table WHERE RefNo = 27"))) { $a .= '"'.query['File'].'",'; } $files = array ($a); i dont know if it will work,just an experimental code Link to comment https://forums.phpfreaks.com/topic/123413-pulling-array-from-mysql-table/#findComment-637396 Share on other sites More sharing options...
lional Posted September 9, 2008 Author Share Posted September 9, 2008 it is still only mailing one attachment Here is my code $query_filename = "SELECT * from attachments WHERE ref_no = '$what_pdf'"; $result_filename = mysql_query($query_filename, $conn); while ($query = mysql_fetch_array(mysql_query("SELECT * FROM attachments WHERE ref_no = '$reference_out'"))) { $a .= '"'.$query['File'].'",'; } $files = array ($a); } // email fields: to, from, subject, and so on $files = array("$files"); $to = $order_mail_out; $from = $email_out; $subject ="Order for Canvas Print Shop Order No. WB$what_pdf"; $message = <<<HERE You have received an order from $fullname_out.<br> To view the complete order click <a href="cps_order.php?quo=$what_pdf" target="_blank">here</a> HERE; $headers = "From: $from"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$mime_boundary}\n"; // preparing attachments for($x=0;$x<count($files);$x++){ $file = fopen($files[$x],"rb"); $data = fread($file,filesize($files[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}\n"; } // send $ok = @mail($to, $subject, $message, $headers); if ($ok) { $mail_result = "<p>mail sent to $to!</p>"; } else { $mail_result = "<p>mail could not be sent!</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/123413-pulling-array-from-mysql-table/#findComment-637580 Share on other sites More sharing options...
lional Posted September 9, 2008 Author Share Posted September 9, 2008 I have got my array to output the string by doing while($row = mysql_fetch_array($result)){ $a .= '"'. $row['filename'] . '",'; and then to minus the last comma $a = substr($a, 0, -1); The strange thing is that if I say this $files = array($a); I get the following error Warning: fopen("DSC02896.JPG","DSC02869.JPG") [function.fopen]: failed to open stream: Invalid argument in D:\htdocs\cps\confirm.php on line 326 But if I type in $files = array("DSC02896.JPG","DSC02869.JPG") ; Which is just the manual input of the files pulled from the db it works fine. but $files = array("DSC02896.JPG","DSC02869.JPG") ; and $files = array($a); is the same thing or am I wrong any help please Link to comment https://forums.phpfreaks.com/topic/123413-pulling-array-from-mysql-table/#findComment-637723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.