MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old February 4th, 2005, 03:04 PM
mack mack is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 mack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 25 sec
Reputation Power: 0
How to remove a character when viewing a table fields data?

My question is reall simple to understand.

When viewing data from a tables field, I need to strip the last character from the results,

example:
My code looks for all email address in the database and displays each email address with a comma after it, so it can easily be copied and pasted into a compose message of an e-mail.

I just want to know how to strip the last characher of the "," comma.

Here is what my code does if you don't understand:


$result = mysql_query("SELECT * FROM emailaddress ORDER BY emailaddress "); // * selects ALL the data
echo "<BR>";
echo "<BR>";
echo "<BR>";
echo "<BR>";
echo "<BR>";
echo "<tt><font size=2>";
while ($myrow = mysql_fetch_array($result)) {
print ("$myrow[emailaddress],<br>");
}
echo "</font></tt>";
?>

The following is in RED is the COMMA that is inserted to seperate each e-mail with a comma but it shows up at the end.

That code displays a comma at the end of listing the e-mail address's, I simply want to remove the comma at the end of the last e-mail listing.

Any ideas?

Reply With Quote
  #2  
Old February 5th, 2005, 04:11 PM
aduroris aduroris is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 7 aduroris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 29 sec
Reputation Power: 0
Hi,

Instead of trying to remove it, why don't you try a different approach.

For example:
Code:
$first_entry = true;

while($row = @mysql_fetch_array($result)) {
  if(!$first_entry) {
    echo(",<br />" . $row['email']);
  } else {
    echo($row['email']);

    $first_entry = false;
  }
}


Perhaps it may be inefficient, but it should work. If anyone has a better approach, please share it (I'm always wanting to learn how to become a better programmer).

Best regards,
Dustin J. Cox

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > How to remove a character when viewing a table fields data?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway