homepage Welcome to WebmasterWorld Guest from 54.166.84.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Defining A Variable
tarheel2002

10+ Year Member



 
Msg#: 4561 posted 7:40 pm on Jul 28, 2004 (gmt 0)

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!

 

jatar_k

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



 
Msg#: 4561 posted 8:42 pm on Jul 28, 2004 (gmt 0)

well,

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

tarheel2002

10+ Year Member



 
Msg#: 4561 posted 4:39 pm on Jul 29, 2004 (gmt 0)

Works like a charm... thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved