hoopplaya4 Posted February 17, 2009 Share Posted February 17, 2009 Hey All, I've got a question, that's probably easy, but for some reason, I can't figure it out. I have a row in my database that stores user emails. I would like to pull the entire array of emails from the database, and place it into a hyperlink. For example: <a href="mailto:johndoe@example.com, janedoe@example.com, jimdoe@example.com">Email Entire Database</a> However, I'm just not quite sure how to do so. So far, I have: <?php $sql = "SELECT usrID, usrEmail, usrFirst, usrLast"; $sql .= " FROM tblUsers"; require("../connection.php"); $rs=mysql_db_query($DBname,$sql,$link); if ($rs) { $row=mysql_fetch_array($rs) ?> <a href='mailto:<?php echo $row["usrEmail"]; ?>'> But this only displaying the first email. How might I print all emails, separated by a comma? I'm sure this is easy, but I'm not sure how to do it! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/145511-solved-print-array-separated-by-comma-probably-easy/ Share on other sites More sharing options...
AV1611 Posted February 17, 2009 Share Posted February 17, 2009 $user='username'; $hostmachine='localhost'; $password='password'; $database='dbname'; mysql_connect($hostmachine,$user,$password); mysql_select_db($database); $query = "SELECT * FROM table WHERE field like 'whatever'"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ do something here with $row[0],$row[1], etc... } This will loop through each result line. Quote Link to comment https://forums.phpfreaks.com/topic/145511-solved-print-array-separated-by-comma-probably-easy/#findComment-763992 Share on other sites More sharing options...
hoopplaya4 Posted February 17, 2009 Author Share Posted February 17, 2009 Thanks for the reply. I sort of understand the "$row[0],$row[1], etc..." but, the name of my column is usrEmail, so would the correct syntax be: $row['usrEmail'][0], or what? Also, the number of results in the table is always changing. For example, I may have 30 emails one day, but 35 the next. So how would I go about it so I don't have to count up using [0],[1],[2], etc? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/145511-solved-print-array-separated-by-comma-probably-easy/#findComment-764352 Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 <?php $user='username'; $hostmachine='localhost'; $password='password'; $database='dbname'; mysql_connect($hostmachine,$user,$password); mysql_select_db($database); $sql = "SELECT usrID, usrEmail, usrFirst, usrLast"; $sql .= " FROM tblUsers"; $result = mysql_query($sql) or die(mysql_error()); $emails = array(); while ($row = mysql_fetch_assoc($result)){ $emails[] = $row['usrEmail']; } $emails = implode(", ", $emails); echo '<a href="mailto: ' . $emails . '">Email Them</a>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/145511-solved-print-array-separated-by-comma-probably-easy/#findComment-764356 Share on other sites More sharing options...
hoopplaya4 Posted February 17, 2009 Author Share Posted February 17, 2009 That was exactly it! Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/145511-solved-print-array-separated-by-comma-probably-easy/#findComment-764381 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.