[thelist] combining multiple fields in db

Ed McCarroll Ed at ComSimplicity.com
Thu Dec 5 09:08:01 CST 2002


You might sidestep the embedded commas issue, as well as the similar
embedded quotes issue, by putting quotes around your descriptions.
You should then make sure that any quotes that are embedded in the
data are doubled, eg:

 In db:  The cat said "meow," and off he ran.
Output:  "The cat said ""meow,"" and off he ran."

Regards,

  Ed

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ed McCarroll                          MailTo:Ed at ComSimplicity.com
ComSimplicity                                      (310) 838-4330
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Liam Delahunty
> Sent: December 05, 2002 6:07 AM
> To: thelist at lists.evolt.org
> Subject: RE: [thelist] combining multiple fields in db
>
>
> Les Lytollis wrote:
>
> >I need to produce a comma delimited text file in the format Artist,
> >Description, Price. My existing db is in the format Artist, Title, Format,
> >Grade, Comments, Cat No., Price.
>
> You could have a problem with the text fields, if commas are in there then
> they could cause the data to mess about. You may want to replace them with
> another character...
>
> $query = "SELECT * FROM table_name WHERE ...WHATEVER...";
> if ($result = mysql_query($query,$connection)){
> 	while ($myrow = mysql_fetch_row($result))	{
> 		$artist = stripslashes($myrow[0]);
> 		$title = stripslashes($myrow[1);
> 		$format = stripslashes($myrow[2);
> 		$grade = stripslashes($myrow[3);
> 		$comments = stripslashes($myrow[4);
> 		$cat_no = stripslashes($myrow[5);
> 		$price = stripslashes($myrow[6);
>
> 		$csv_array[] = "$artist, $title $format $grade $comments $cat_no, $price";
> 	}
> }
>
> then do whatever you want to do with the csv_array. Such as sort it and
> output the file.
>
> Kind regards,
> Liam Delahunty
> Mega Products Limited, 10-11 Moor Street, Soho, London W1D 5NF
> t: 020 7434 4201 f: 0870 135 8412
> http://www.liamdelahunty.com/ web/ design/ database/ programming
> http://www.britstream.com/ Hosting/ Domain Names From UKP 7.50 p.a.
>
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>




More information about the thelist mailing list