wright67uk Posted February 9, 2011 Share Posted February 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/227196-using-returned-sql-query-values-as-variables/ Share on other sites More sharing options...
requinix Posted February 9, 2011 Share Posted February 9, 2011 Is $row["email"] not working for you? Why switch to individual variables? Quote Link to comment https://forums.phpfreaks.com/topic/227196-using-returned-sql-query-values-as-variables/#findComment-1171976 Share on other sites More sharing options...
wright67uk Posted February 9, 2011 Author Share Posted February 9, 2011 This is because the returned values are email addresses and i would like to put the individual variables into my mail string. eg. mail( "$value1, $value2, $value3", "Header","$message" ); Quote Link to comment https://forums.phpfreaks.com/topic/227196-using-returned-sql-query-values-as-variables/#findComment-1171982 Share on other sites More sharing options...
Muddy_Funster Posted February 10, 2011 Share Posted February 10, 2011 while ($row = mysql_fetch_array( $result )) { $message .= $row['email'].";" ; } should fill all your mail addresses into a format that will send. Quote Link to comment https://forums.phpfreaks.com/topic/227196-using-returned-sql-query-values-as-variables/#findComment-1172310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.