mysql - PHP get the strings separate to store in the array


I am working on my PHP to fetch the data from the mysql database. I have got a problem with storing the filename in the array using the values when I have stored both filenames in a database.

Here is what I have stored in the blob:

draft_attachment - Copy.rar

Here is the code:

$mailbox = $link->prepare("SELECT * FROM draft WHERE id = ?");

// set the resulting array to associative
$row = $mailbox->fetch(PDO::FETCH_ASSOC);
$attachments = array();

if($mailbox->rowCount() == 1)
    $attachment = array();
    $draft_to = htmlspecialchars($row['to_email']);
    $draft_subject = quoted_printable_decode($row['subject']);
    $draft_message = $row['message'];
    $attach[] = $row['attachments'];

When I try this:

$attach[] = $row['attachments'];

It will store both strings in the array:

   [0] => draft_attachment.rar
draft_attachment - Copy.rar

So I have tried this:

$attachments = array();  
$i = 0;

if($mailbox->rowCount() == 1) {
    $attachments[$i] = $row['attachments'];

It wont store the strings separate so I dont know what to do.

Here is what I want to achieve:

   [0] => draft_attachment.rar
   [1] => draft_attachment - Copy.rar

Can you please show me an example how I could get both strings to go separate so I could be able to store them in the array using the value?

Thank you.




you can use explode function, something likeexplode("\n", $row['attachments'])

People are also looking for solutions to the problem: php - Storing multiple values in $_SESSION array


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.