Re: Array to List

From: Date: Mon, 11 Aug 2003 20:11:50 +0000
Subject: Re: Array to List
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159187@lists.php.net to get a copy of this message
From: "James Johnson" <james@smb-studios.com> > Actually, I'm using $campusList for a SQL statement: > > SELECT name FROM campuses WHERE inst_id IN ('$campusList'); > > It wasn't working until I found out that $campusList needs to look like > '1','2','3'. > > $campusList = implode( ', ', $_POST['campus'] ); > > Returns 4,2,3 (whatever was selected) > > I've looked in the manual on implode, but don't see how to surround each > value with single quotes. Is there another function that will do this? You don't need the quotes if the values are integers, but if you insist... $campusList = "'" . implode("','",$_POST['campus']) . "'"; The implode "pattern" is a single quote, comma, single quote, then surround the whole implode result by single quotes to complete it. ---John Holmes...

« previous php.general (#159187) next »