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 [email protected]; [email protected]; [email protected];}echo "Emails Will be $email"; //Here I get: Emails Will be [email protected]Now 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 [email protected]; [email protected]; [email protected] <--- no ; at the end.Thanks,Roman Link to comment https://forums.phpfreaks.com/topic/18075-help-with-while-loop/ 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 [email protected]; [email protected]; [email protected];$allemails = $allemails.$email.';';}$allemails = $str = substr($allemails,0,strlen($allemails)-1);echo '<br />';echo $allemails;?>[/code] Link to comment https://forums.phpfreaks.com/topic/18075-help-with-while-loop/#findComment-77496 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); //--> [email protected]; [email protected]; [email protected]?>[/code] Link to comment https://forums.phpfreaks.com/topic/18075-help-with-while-loop/#findComment-77509 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 Link to comment https://forums.phpfreaks.com/topic/18075-help-with-while-loop/#findComment-77548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.