|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > How to remove a character when viewing a table fields data? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|