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!!! Quote Link to comment 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']"; Quote Link to comment 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. Quote Link to comment 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" Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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.