ohdang888 Posted March 30, 2008 Share Posted March 30, 2008 i have a column called tags in my table.... the info in it is like this car, motor, automobile, gas, drive, road How do i separate those into different variables???? like.. $var1 = 'car'; $var2 = 'motor'; etc. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/ Share on other sites More sharing options...
MadTechie Posted March 30, 2008 Share Posted March 30, 2008 you can use the list() function but whats wrong with using an array? or even setting them $var1 = $row['car']; etc Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504412 Share on other sites More sharing options...
ToonMariner Posted March 30, 2008 Share Posted March 30, 2008 $qry = "SELECT `tags` FROM `your_table`"; $qry = mysl_query($qry); if (mysql_num_rows($qry) > 0) { $vars = array(); while($row = mysql_fetch_assoc($qry)) { $vars[] = $row['tags']; } $vars = array_unique($vars); extract($vars,EXTR_PREFIX_ALL, 'var'); $number = count($vars); for($i=0;$i<$number;$i++) { $temp = "var$i"; echo $$temp; } } something like that shoudl do the trick... Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504414 Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Author Share Posted March 30, 2008 didn't work. (i found the errors, but it still didn;t work) thanks though MadTechie: I think i will need to do the second one, but one thing... All this info in is under 1 column and there is anywhere between 0 and 10 tags in it. So the list() won't work... (i think ???) So i'm really confused on this, how can i put these on in array or set? Thanks for helping.. Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504423 Share on other sites More sharing options...
MadTechie Posted March 30, 2008 Share Posted March 30, 2008 using ToonMariner code <?php $qry = "SELECT `tags` FROM `your_table`"; $qry = mysl_query($qry); if (mysql_num_rows($qry) > 0) { $vars = array(); $i=1; while($row = mysql_fetch_assoc($qry)) { $vars["var$i"] = $row['tags']; $i++; } //debug echo "heres the array<br><pre>"; print_r($vars); //create variables extract($vars); echo "$var1 <br>"; echo "$var2 <br>"; echo "$var3 <br>"; echo "$var4 <br>"; //etc ?> Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504439 Share on other sites More sharing options...
sasa Posted March 30, 2008 Share Posted March 30, 2008 try <?php $tags = 'car, motor, automobile, gas, drive, road'; $tags = explode(',', $tags); $num = count($tags); $i = 0; while ($i < $num){ $name = 'var'.($i + 1); $$name = trim($tags[$i++]); } echo $var3; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504516 Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 really alll you need to do is set the $varable names to what you want really this is a flash way lol. you mean this re edted sorry......... <?php $tags = 'car, motor, automobile, gas, drive, road'; $tags = explode(',', $tags); //set within the varable names $car="redarrow"; for($i=0; $i<count($tags); $i++){ $res[]=trim($tags[$i]); } foreach($res as $x){ echo " All set varables are: $$x<br>"; } echo "car is now: $car"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504526 Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Author Share Posted March 30, 2008 that works! Thanks~! Quote Link to comment https://forums.phpfreaks.com/topic/98557-separate-tag/#findComment-504784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.