Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic for e-mail program 3

Status
Not open for further replies.

EnsignPulver

IS-IT--Management
Joined
Apr 18, 2004
Messages
17
Location
US
Hello Friends,

I have the following little snippet:

$email=mysql_result($result,$i,"email");

echo "<b>$email,<br><hr><br>";

++$i;
}

?>

What I get is x@z.com, p@t.com,

What I need is x@z.com, p@t.com

I need to build a little logic to say "add commas between each email address, then don't add a comma after the last one!"

The object of my script is to provide the contents of my mail field so that people can copy and paste all of the group's email addies into their mail program.

Thanks for any guidance!! I'm stuck.

ENS Pulver
 
just a quick solution i use everytime:
Code:
 $result = substr($result, 0, -1);
;) just take you're full string and remove the last char (comma).

if u have like
Code:
/* for every result do*/ $result .= "<b>$email,<hr><br>";
or whatever just use
Code:
 $result = substr($result, 0, -9);
(remove last 9 chars.)

i find this more usefull than all the if < than max then add comma else don't.

just my 2 cents ;)

jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
Thanks again to everyone for their contributions. I wanted to tell you that OUR little program was extremely well-received.

Since it's extremely important that we know where all our guys are at all times -- and this was an application that provides emergency contact info -- we all contributed a little to the safety of a really good group of people.

ENS
 
Even if this discussion is closed, here's a different approach:
You need not print out everything right away. Accumulate it into an array and implode it.
Code:
while ($row = mysql_fetch_assoc($res)){
   $recipients[] = $row['email'];
}
echo(implode(',',$recipients));
No need to count anything or to skip through the result set etc.
 
Thanks, DR.

Here is guys. Our final result. There is some simple Javascript that allows it to be copied to the clipboard (only in IE, sadly, and I use Firebird myself...). I haven't been able to learn the copy to clipboard method for Mozilla, and it's not worth it considering all my users -- all -- will be using IE.

The file is an include that's called by my "view all entries" page.

I learned a lot. Thanks everyone.

Code:
<table width="100%" border="0">
  <tr>
    <td width="33%"><?
echo "<form action=\"search.php\" method=\"post\">";
echo "Choose Search Type: ";
echo "<select name=\"searchtype\">";
echo "<option value=\"lastname\">Last Name";
echo "<option value=\"firstname\">First Name";
echo "<option value=\"homephone\">homephone";
echo "</select><br>";
echo "Enter Search Term: ";
echo "<input name=\"searchterm\" type=text><br>";
echo "<input type=submit value=\"Search\">";
echo "</form>";
?>
</td>
    <td><SPAN ID="copytext" STYLE="height:20;width:162;background-color:#846A75">
<TEXTAREA ID="holdtext" STYLE="display:none;">
<?
$username="bleebloo";
$password="blaugh";
$database="bleeg";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM `phonelist` WHERE email IS NOT NULL";
$result=mysql_query($query);
$num = mysql_num_rows($result);
for ($i=0; $i<$num-1; $i++)
{
$line = mysql_result($result,$i,"email");
echo "$line,";
}
$line = mysql_result($result,$i,"email");
echo "$line";
?>

</TEXTAREA>
</span> <br>
<BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> 
</td>
    <td>&nbsp;</td>
  </tr>
</table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top