Currently I have a string variable as follows: $address=$address1.", ".$address2.", ".$district.", ".$town.", ".$county.", ".$postcode; Code (markup): And I have a JavaScript Tooltip that displays $address onClick: echo ' <a href="#" onclick="Tip(\''.$address.'\'); return false" '; Code (markup): This works fine, but there is one problem - sometimes a client's address does not have a district, and as a result an extra comma gets displayed. Now I did create a function with some IF statements in to check what data is there and what isn't but I had trouble making a call to this function within the onClick JavaScript function. What is the best way of going about this?
I just realised I cant use a function as it cant get declared more than once... Is there any way I can include IF statements in my $address variable?
It seems that you are quite up to scratch with PHP. I would suggest, doing a str_replace() on whereever the string ", ," is and replacing it with ",". This is the most simple solution I can suggest.
Here u go $district = (empty($district)) ? '' : $district.", "; $address=$address1.", ".$address2.",".$district.$town.", ".$county.", ".$postcode; Code (markup):