0

I have this PHP Code:

$number = substr_replace($_POST["number"],"44",0,1);

$sql="SELECT * from channel_did where did LIKE '%".$number."%' AND (client_id = '' OR client_id IS NULL or client_id = '611') AND (extension_id = '' OR extension_id IS NULL) ";
$rs=mysql_query($sql,$pbx01_conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
    $numbers_list = $result["did"].'<br>';
    $email_body = '<font face="Arial">
    Hello, here are some numbers that you have requested.<br><br>
    Please be aware that these numbers are in a public pool and not reservered, therefore they could be assigned to another client at any time.<br><br>
    Please make your choice as soon as possible to guarantee the number you require.<br><br>
    '.$numbers_list.'<br><br>
    Kind Regards,<br><br>
    Customer Services<br>
    Integra Digital<br><br>
    tel: 01702 66 77 27<br>
    email: [email protected]<br>
    web: www.integradigital.co.uk
    </font>';
}

    echo $email_body;

sendemail($_POST["emailto"],"Integra Digital <[email protected]>","VoIP Phone Numbers You Requested",$email_body,"[email protected]");

it selects rows from a table and i need it to email just one email with a list of the rows

when i run the SQL i know there are about 10 rows (did)

when it sends the email, its using the $email_body variable but only putting one row in the email.

i have created a $numbers_list variable that should have a list of all the rows but it only does one row.

1
  • 2
    mysql_* is now deprecated. Please use either mysqli or PDO. Commented Jul 31, 2013 at 12:15

2 Answers 2

6

create an array(), push the rows data to it.. and use implode() in $email_body;

try this

while($result=mysql_fetch_array($rs))
{
    $numbers_list[] = $result["did"];

}

 $email_body = '<font face="Arial">
    Hello, here are some numbers that you have requested.<br><br>
    Please be aware that these numbers are in a public pool and not reserved, therefore they could be assigned to another client at any time.<br><br>
    Please make your choice as soon as possible to guarantee the number you require.<br><br>
    '.implode('<br>',$numbers_list).'<br><br>
    Kind Regards,<br><br>
    Customer Services<br>
    Integra Digital<br><br>
    tel: 01702 66 77 27<br>
    email: [email protected]<br>
    web: www.integradigital.co.uk
    </font>';

and as always mysql is deprecated so have a look to mysqli or PDO

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

1 Comment

Awesome method. I would've done it by concatenation like others are suggesting, but this deserves a +1 for being elegant.
0
$number_list = Array();
// no need for unneccesary variables
// no need for unneccesary *, SELECT did
$sql="SELECT did from channel_did 
        WHERE       did LIKE '%".substr_replace(mysql_real_escape_string($_POST["number"]),"44",0,1)."%' 
        AND (   client_id = '' 
            OR  client_id IS NULL 
            OR  client_id = '611'
            ) 
        AND (   extension_id = '' 
            OR  extension_id IS NULL
            ) ";
$rs=mysql_query($sql,$pbx01_conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
    $numbers_list[] = $result["did"].'<br>';

}
 $email_body = '<font face="Arial">
    Hello, here are some numbers that you have requested.<br><br>
    Please be aware that these numbers are in a public pool and not reservered, therefore they could be assigned to another client at any time.<br><br>
    Please make your choice as soon as possible to guarantee the number you require.<br><br>
    '.implode(',',$numbers_list).'<br><br>
    Kind Regards,<br><br>
    Customer Services<br>
    Integra Digital<br><br>
    tel: 01702 66 77 27<br>
    email: [email protected]<br>
    web: www.integradigital.co.uk
    </font>';
echo $email_body;

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.