dizel247 Posted August 20, 2006 Share Posted August 20, 2006 Hello,Can some one help me with while loop expression.I am looping from the database email adresse. This is how I do it.//Select User Email from Database$rsUserEmail = mysql_query("SELECT * FROM contacts WHERE carrier_id = '$cid' AND contacts.rates = '1'")or die(mysql_error()); // store the record of the "example" table into $rowwhile($row = mysql_fetch_array($rsUserEmail)){// Print out the contents of the entry$email = $row['contact_email']; echo "$email; ";// Here I get result a@aol.com; b@aol.com; c@aol.com;}echo "Emails Will be $email"; //Here I get: Emails Will be c@aol.comNow when I refer to the $emails I only get one email.My question is.. How do I store loop in the variable. So I can refrence it anytime. Also I need my result to be a@aol.com; b@aol.com; c@aol.com <--- no ; at the end.Thanks,Roman Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 20, 2006 Share Posted August 20, 2006 You will need to use a differant variable name to store it all for later, plus you can use substr() to take off the last character. [code]<?php//Select User Email from Database$rsUserEmail = mysql_query("SELECT * FROM contacts WHERE carrier_id = '$cid' AND contacts.rates = '1'")or die(mysql_error()); // store the record of the "example" table into $row$allemails = '';//give it some value other wise php5 gives a noticewhile($row = mysql_fetch_array($rsUserEmail)){// Print out the contents of the entry$email = $row['contact_email']; echo "$email; ";// Here I get result a@aol.com; b@aol.com; c@aol.com;$allemails = $allemails.$email.';';}$allemails = $str = substr($allemails,0,strlen($allemails)-1);echo '<br />';echo $allemails;?>[/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted August 20, 2006 Share Posted August 20, 2006 or use an array[code]<?php$rsUserEmail = mysql_query("SELECT contact_email FROM contacts WHERE carrier_id = '$cid' AND contacts.rates = '1'") or die(mysql_error()); $email = array();while($row = mysql_fetch_array($rsUserEmail)){ $email[] = $row['contact_email']; // add to array}// when you want to use them$allemails = join ('; ', $email); //--> a@aol.com; b@aol.com; c@aol.com?>[/code] Quote Link to comment Share on other sites More sharing options...
dizel247 Posted August 20, 2006 Author Share Posted August 20, 2006 Thank you all for a quick reply.Best Regards,Roman Quote Link to comment 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.