![]() |
|
#1
|
|||
|
|||
Removing the last comma in a stringhi,
i'm trying to use the left() function to remove an additional comma at the end of a string but it won't parse. Here is a section of code that is trying to pull column names and then gets placed into an Insert statement. $get_columns=$new_db->query("explain grades"); while($row=$new_db->fetch_row($get_columns)) { //an index to loop through the column names $i=0; $column_name=$row[$i]; //create a table to list all of the current columns $names .="$column_name,"; //increment index to go to the next column name $i++; } $msg=left($names, len($names)-1); $newmsg="Insert into grades("$msg")..........."; Is there something that has to be included so the parser knows what the left function is and is there maybe a better way to remove the last comma? I would appreciate any help, KurtM |
|||
|
#2
|
|||
|
|||
|
Quote:
I think your problem is the line: $newmsg="Insert into grades("$msg")..........."; Try PHP Code:
The speech marks are the start and stop markers for you string. If you want to use one inside a string you have to place the backslash infront of them to tell the parser not to see them as actual code. Hope that helps |
|
#3
|
||||
|
||||
|
Quote:
Hello Kurt, Sorry I haven't had the time to go through your issues in the PHP forum recently but I can quickly post an alternative solution you can try: use the rtrim() function to remove the last comma... like this: PHP Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AdSonar spider / bot useragent string | JdS | Advertising & Affiliates Forum | 1 | 10-Mar-2006 17:05 |
| Including Maps and strings?? | maddie | C++ Forum | 17 | 05-Jul-2004 07:25 |
| Problem putting variables cumulatively into a string, | warny_maelstrom | C Programming Language | 3 | 05-Feb-2004 10:29 |
| [function] AutoLink (converts URLS into links inside a string) | JdS | PHP Code Library | 0 | 26-Jan-2004 06:02 |
| storing a token pointer as a string | CoreLEx | C Programming Language | 1 | 07-Oct-2003 12:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The