Jump to content

Using sql results as variables


wright67uk

Recommended Posts

How can i put returned values from an sql query, into variables.

If the returned values from a query were; email1@com, email2@com, email3@com

how would i go about puting them into variables?

 

$value1 = (1st returned value from my sql query, in this case it would be email1@com)

$value2 = (2nd returned value from my sql query, in this case it would be email2@com)

$value3 = (3rd returned value from my sql query, in this case it would be email3@com)

 

$code = $_GET['postcode'];
$message = $_GET['message'];
$emailad = "email@email.comuk";
$shortcode = substr($code,0,2);
$result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3")
or die(mysql_error());  
echo "<h2>Business Names:</h2>";                     
while ($row = mysql_fetch_array( $result )) 
{
$message .= "\r\n". $row['email'] ;
}
echo nl2br ($message); 
mail( "$emailad", "Header","$message" );
echo "<br>" . "Thank you for using our mail form.";
?>
</body>
</html>

 

Thankyou for any ideas, or suggestions.

Link to comment
Share on other sites

Thankyou for the replys.  Ive tried too put this together, and i still get the correct html returned, but unfortunately no emails are sent.  Have I put this together wrong?

 

$code = $_GET['postcode'];
$message = $_GET['message'];
$emailad = "email@email.comuk";
$shortcode = substr($code,0,2);
$result = mysql_query("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3")
or die(mysql_error());  
echo "<h2>Business Names:</h2>";                     
while ($row = mysql_fetch_array( $result )) 
{
$message .= "\r\n". $row['email'] ;
}
$i = 0;
while($row = mysql_fetch_assoc($result)) {$value[] = $row['Email'];}

{
$i++;
switch($i)
{
case 0:$value1 = $row['Email'];
break;
case 1:$value2 =$row['Email']; 
break;
case 2:$value3 =$row['Email'];
break;
}}
echo nl2br ($message); 
mail( "$value1, $value2, $value3", "Header","$message" );
echo "<br>" . "Thank you for using our mail form.";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.