PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have been trying to produce a formatted list using PHP code. The output must be in this format and use the "return $value" code for output:
thing1a;thing1b
thing2a;thing2b
etc.
It is to be included in a Joomla extension called ContentBuilder.
I have adapted a section of code that was posted on another forum but I can only get it to return one set of values (thing1a;thing1b) even though there are many rows in the table. It currently returns the set of values for the last row in the table. I believe that I need to add an array to the below code and a variable that can store and then return all the values rather than just one value. However, I've been trying for two days and can't get a result. I should point out that I'm a marketing person not an IT expert and I'm just trying to produce a working example of something.
Near the bottom of your code, your `;` was being interpreted by the php engine, because it was not enclosed in single quotes. See the corrections below, I hope it helps.
Every time that code executes (which it will because it's perfectly fine) it will overwrite the previous $value. What you need to use is the .= operator which will append the string to $value.
Thanks for the quick replies. I had the ".=" in my original code and removed it because I had no values returned. Maybe it is an issue with Joomla/ContentBuilder interpretting the code correctly. Perhaps I can find another way of doing the same thing. Thanks.
I think it must be the Joomla extension that cannot handle this type of code.
Have have tried another option to concaternate $value = $value."$opt1;$opt2"."\n"; but this doesn't work either. Any other way I can construct this code to get the required result output?
Debug your code within the for loop (print_r($value);) and see what gets printed. If that doesn't work, run the query on a SQL client/command line and see what you get.
I think I have found the source of the problem. The \ (backslash) of "\n" is being stripped out of the code when saved in the Joomla extension hence the result is something like this value1;code1value2;code2, which is not displayed because of the missing line break.
I am using Joomla 1.7.2 with PHP 5.2.17. I tried with a more recent version of PHP but I get the same issue. Any suggestions? Maybe there is another way of doing a line break.
Thanks for the reply but the <br /> can not be returned using 'return' so it doesn't work. I'm trying to find a way around the fact that I can't use "\n" so I tried <br /> which will echo the correct results. I figured there may be away of assigning the echo to a variable but apparently not.
I've just tried a new approach. I've included the part of the code containing the \ in an external file that is inserted but I still get the same issue.