1

Would this work? I know you can concatenate variables this way.

    while ($row = mysql_fetch_array($result)) {
          $recipients[] = $row['phone'] . $row['carrier'];
    }

    while ($row = mysql_fetch_array($result)) {
        $recipients[] .= $row['email'];
    }
1
  • @Jack Yes, it does work in fact! But I feel like it's bad practice and got good ideas below. Commented Nov 27, 2012 at 0:13

2 Answers 2

1

It won't work since you have already reached the end of the fetch (i.e. mysql_fetch_array will always return false in the second loop).

Moreover, it probably wouldn't be a good idea if you wanted have some indicator of phone vs. email, but I guess you don't:

$phones = array();
$emails = array();
while ($row = mysql_fetch_assoc($result)) {
   $phones[] = $row['phone'] . $row['carrier'];
   $emails[] = $row['email'];
}
$recipients = $phones + $emails;

Also, didn't anyone tell you to use PDO or mysqli?

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I will be converting to mysqli. I'm late ;)
Also, I like your answer. That looks good! My code worked, but this look more efficient.
Okay -- anyone reading this should apparently know that you can use mysql_fetch_array twice in a row!
1

Assuming you have two separate queries and they both return the same number of results in the exact same order, you should use a counter to help you find the right entry to modify:

$i = 0;
while ($row = mysql_fetch_array($result)) {
    $recipients[$i++] .= $row['email'];
}

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.