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 protected]";
$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
https://forums.phpfreaks.com/topic/227195-using-sql-results-as-variables/
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 protected]";
$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.";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.