wilsonf1 Posted July 13, 2012 Share Posted July 13, 2012 Ok so I have 8 database fields for 8 numbers. I also have 8 tags in my HTML for those numbers. I was going to use a FOR loop to loop through the tags, and replace each with the correpsonding db field, but I couldn't get it to work so now have 8 lines like so: $this->Notes1HTML = str_replace("<Number1>", $this->formatPhoneNumber($this->directoryDataDB->Number1), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number2>", $this->formatPhoneNumber($this->directoryDataDB->Number2), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number3>", $this->formatPhoneNumber($this->directoryDataDB->Number3), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number4>", $this->formatPhoneNumber($this->directoryDataDB->Number4), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number5>", $this->formatPhoneNumber($this->directoryDataDB->Number5), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number6>", $this->formatPhoneNumber($this->directoryDataDB->Number6), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number7>", $this->formatPhoneNumber($this->directoryDataDB->Number7), $this->Notes1HTML); $this->Notes1HTML = str_replace("<Number8>", $this->formatPhoneNumber($this->directoryDataDB->Number8), $this->Notes1HTML); Say I was looping round with $i being my counter, I could use: "<Number" . $i ".>" But I couldn't replace it with $this->directoryDataDB->Number . $i could I? Is there anyway round it or shall I stick with my 8 liner Link to comment Share on other sites More sharing options...
birbal Posted July 13, 2012 Share Posted July 13, 2012 $num="number$i";$this->directoryDataDB->$num; 1 Link to comment Share on other sites More sharing options...
wilsonf1 Posted July 13, 2012 Author Share Posted July 13, 2012 $num="number$i";$this->directoryDataDB->$num; You da man! Thanks. Very simple, I just didn't have my thinking cap on that one Link to comment Share on other sites More sharing options...
justsomeguy Posted July 13, 2012 Share Posted July 13, 2012 I believe this also works: $this->directoryDataDB->{'Number' . $i} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now