tbare Posted September 9, 2008 Share Posted September 9, 2008 here's what i want to do: <?php $tempID = "random"; $a = "\$humor_video_"; str_replace('$a', $a, $b); $tempModded = $b.$tempID."_modded_day2"; ?> where $humor_video_random_modded_day2 = "Dec 3"; so i want to be able to echo $tempModded; and return "Dec 3" is this possible? and if so, how? i'm pulling my hair out here... basically, i'm in transition from flat files to mySQL, and getting stuff working in the "in between" stages.. TIA. Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/ Share on other sites More sharing options...
genericnumber1 Posted September 9, 2008 Share Posted September 9, 2008 are you talking about variable variables? $str1 = 'foo'; $foo = 'bar'; echo $$str1; // Outputs "bar" you can do it, but it's terrible practice... I'd suggest using arrays or finding a better alternative. Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637168 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 not exactly... basically, "random" is a column in a row in a table (sounds a lot like the house that jack built....) other columns in the same table include "zp" "snl", etc... i need a good way to get $humor_video_[columnContent]_modded_day however necessary So: echo $humor_video_random_modded_day //print "Jun 2" echo $humor_video_zp_modded_day //print "Jan 19" echo $humor_video_snl_modded_day //print "Dec 5" or whatever those variables happen to be.... Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637171 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 nothing? Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637201 Share on other sites More sharing options...
genericnumber1 Posted September 9, 2008 Share Posted September 9, 2008 I just don't understand :X Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637214 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 ok... i'll try again i have a file "updated.php" that has when all categories have been updated last with code like (for simplicity's sake..): <?php $humor_video_random_modded_day = "Jun 2"; $humor_video_zp_modded_day = "Jan 19"; $humor_video_snl_modded_day = "Dec 2"; ?> i have a table that has in a column the content: random, zp, snl; each in a different row. i have a for() loop that goes through and gets all the content from that table, and echos some info. i want to be able to dynamically get the information in the updates.php site using the content in the table (random, zp, snl) in the variable... so: $lastMod = "$humor_video_".$forloopArray[$i][4]."_modded_day"; but (obviously) the above code doesn't work, so i'm looking for a piece that will... i'm hoping that this explains it a little better... Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637219 Share on other sites More sharing options...
genericnumber1 Posted September 9, 2008 Share Posted September 9, 2008 can you post the code you're speaking of? $tempID = "random"; $frontVar = "humor_video_"; $tempModded = ${$frontVar.$tempID."_modded_day2"}; is all I can really come up with from your original question... this will set $tempModded to the value held in $humor_video_random_modded_day2 (not that it's good practice). Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637229 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 gah.. you're a genius!! that's exactly what i needed... effing squiggly brackets! i swear i tried every combination except that one (apparently....) Thanks a ton! Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637234 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 ...oh yeah, and i know it's not good practice, but it's only temporary until i get my (hundreds) of videos on the site into the db... which will probably take some time.... Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637235 Share on other sites More sharing options...
genericnumber1 Posted September 9, 2008 Share Posted September 9, 2008 as long as you put a comment for yourself in the future! Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637236 Share on other sites More sharing options...
tbare Posted September 9, 2008 Author Share Posted September 9, 2008 haha.. actually, i'm using filemtime() now to get the date, and in the future, date will be stored in the db, so the entire function will be different, so there won't need to be comments, because it will be re-written from scratch, basically.. thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/123364-solved-nesting-variables/#findComment-637237 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.