You open and close single-quotes around your test condition, thatās correct. But then the true condition return isnāt quoted correctly - thereās a double-quote which will start the return string, then another that will end it where you probably want it to be the start of the URL. I think it should be nearer this:
For consistency there, Iāve used single quotes to surround strings so that I can include double-quotes within those strings. As Iām not expecting PHP to substitute variable values inside any of those strings, it will work.
Iām not sure your HTML is correct, though - you seem to open and close a hyperlink with no content, then close it again after youāve output the image. If your intention was to use the image as the link, then this might be better, by dropping the closing tag from within your conditional string.
You canāt mix the ternary operator (the [ condition ? true-operation : false operation ] construction) with if-then-else in the way you are talking about, as far as I know.
It seems to work with 2 redirections only. What do I need to do to continue.? I though you only need to repeat else, but maybe I need some other code ā¦ I know nothing of php
You canāt do that in that way with the ternary operator. In fact how could you? You provide a condition which is tested, the first operation is done if the test returns true, otherwise the other operation is done. So under what circumstances would the third operation be done, or the fourth or any other? The test is either true or not, so it only has two outcomes.
If you want to check for multiple different conditions, then youād need to use a series of if-then-else or, better in my mind, a switch() construction.
But, if your links are just using the value of $chain as the id parameter, why not do something like this?
If thereās anything at all in the $chain variable, it will be used as the id. If there is not, it will link to the default index.
Note that Iāve assumed here that $chain will exist. If there is a chance it does not, you must check for that so as to not get errors for a non-existent variable.
Thatāll be quotes again - if you look at the link you can see that itās actually putting the string ā$chainā in there, rather than substituting the value. If it really is based on that value, any other way would be excess.
Remember that if you surround the entire string in single-quotes, as I mentioned above, php doesnāt substitute variable values, it only does this when you surround with double quotes. So you either have to concatenate the variable, or surround the whole thing with double quotes - which you canāt do here because you use double-quotes inside the string as well. Well, you can, but you have to escape the quotes inside the string, which adds some confusion in my mind, I prefer to keep it neat.