Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Defining A Variable



7:40 pm on Jul 28, 2004 (gmt 0)

10+ Year Member

Help, I can't figure this one out...

I want to create a comma delimited list of results from a MYSQL query and store it as $variable so that I can use it in a SELECT IN($variable) statement later on.

Thanks in advance!


8:42 pm on Jul 28, 2004 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member


1. construct your query
2. use mysql_query to get your results from the db
3. use a loop to append each value to a variable

for int coltype
$var1 = "";
while($row = mysql_fetch_array($result)) {
$var1 .= $row['mycol'] . ',';

for varchar coltype
$var1 = "";
while($row = mysql_fetch_array($result)) {
$var1 .= "'" . $row['mycol'] . "',";

4. chop the trailing comma
$var1 = substr($var1,0,strlen($var1)-1);

5. use this var to create your new query


4:39 pm on Jul 29, 2004 (gmt 0)

10+ Year Member

Works like a charm... thanks!

Featured Threads

Hot Threads This Week

Hot Threads This Month