kirk112 Posted August 16, 2007 Share Posted August 16, 2007 Hi Thought this was going to be straight forward - (could be having a mental block); From a MySQL query I have: $row['page_title'] which = "Page Title - $row_jobs['job_title']"; if i echo $row['page_title'] it prints out 'Page Title - $row_jobs['job_title']' instead of 'Page Title - store manger' What am I missing??? Thanks for your help!!! Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/ Share on other sites More sharing options...
LiamProductions Posted August 16, 2007 Share Posted August 16, 2007 $row['page_title'] which = "Page Title -" . "$row_jobs['job_title']"; Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/#findComment-325864 Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 i don't know how liamproduction's reply will actually help you (i myself have no idea what he's trying to say). if you've stored the variable as that string, you'll need to evaluate it in order to have the variables interpolated as you desire. from the PHP manual for eval(): <?php $string = 'cup'; $name = 'coffee'; $str = 'This is a $string with my $name in it.'; echo $str. "\n"; eval("\$str = \"$str\";"); echo $str. "\n"; ?> The above example will output: This is a $string with my $name in it. This is a cup with my coffee in it. in this case, $row['page_title'] is the $str value. you may hit parse errors, since you usually need to encase array values in braces {} in order to have them interpolated properly. Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/#findComment-325871 Share on other sites More sharing options...
Gamic Posted August 16, 2007 Share Posted August 16, 2007 to do this without using the "dot" operator to concatenate, you can do this: $row['page_title'] = "Page Title - {$row_jobs['job_title']}"; The curly braces can be used around variables to show that "this whole thing" is the variable. $variableName="Hello"; $test[$variableName]="World"; echo "$variableName {$test['Hello']}"; //should output "Hello World" Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/#findComment-325874 Share on other sites More sharing options...
LiamProductions Posted August 16, 2007 Share Posted August 16, 2007 He said the last bit of his variable was'nt printing so i fixed it Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/#findComment-325878 Share on other sites More sharing options...
akitchin Posted August 16, 2007 Share Posted August 16, 2007 He said the last bit of his variable was'nt printing so i fixed it $row['page_title'] which = "Page Title -" . "$row_jobs['job_title']"; the word which will toss a parse error, and "$row_jobs['job_title']" will also toss a parse error. Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/#findComment-325880 Share on other sites More sharing options...
kirk112 Posted August 17, 2007 Author Share Posted August 17, 2007 Thanks for your help got it to work prefectly with eval - it tried to use that before but get parse errors, needed the {} around the array Link to comment https://forums.phpfreaks.com/topic/65256-solved-variables-in-variables/#findComment-326489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.