This is driving me insane I swear is seems like I am doing something right one day and wrong the next I am trying to pass a variable into a URL string in a while loop echo "<a href=$go'sort='$rows->name'&order=ASC>UP</a>"; Code (markup): i have tried every combination <a href='.$go.'sort='.$rows->name.'&order=ASC>UP</a> Code (markup): <a href=$go'sort='$rows->name'&order=ASC>UP</a> Code (markup): <a href=$go'sort=$rows->name&order=ASC>UP</a> Code (markup): the last one almost works but the problem is that I can't take out the apostraphe after $go because it will make $gosort Can someone help me out and please explain why I think the first one should work.
echo "<th><a href=''.$go.'sort='.$rows->name.'&order=ASC'>UP</a>" Code (markup): I am losing the end of it..... sort and order do not display
the one i suggested should do just fine (i did forget a double quote after ASC though ): echo '<th><a href="' . $go . 'sort=' . $rows->name . '&order=ASC'">UP</a>'; PHP: you just have to make sure you're opening and closing the correct quotes: if you wrap the entire string in single quotes, you have to place the variables outside the string, otherwise the value of the variable won't be inserted into the string. If you use double quotes, it doesn't matter.
You know you should familiarize yourself with sprintf and family, you avoid all this nonsense when you use these functions. <? $go = "http://krakjoe.com/post-ajax.php?"; $rows = new stdClass ; $rows->name = 'TESTING'; printf( '<a href="%ssort=%s&order=ASC">UP</a>', $go, $rows->name ); ?> PHP:
The biggest advantage for web programmers using sprintf over echo and print would be as you see here, I just wrote the url, no messing with '. $this .' sort of nonsense. There are others too, sprintf can format characters in many different ways without the use of auxiallary functions, for example changing integers to hex values, like rgb colours to hex representations of the same, which is useful for many things and is just a one liner <? printf("#%02X%02X%02X", 15, 15, 15 ); ?> PHP: I had something else aswell but its gone out of my head and I've sat here for ten minutes thinking about what it was .... it'll come to me and I'll post it .... Just the fact that it should cut down your syntax errors and unexpected behaviour while building and manipulating strings is enough to use it right ?
Unless I misunderstand what you are trying to do, shouldn't there be something in the URL to indicate it contains arguments. For instance: echo '<a href="' . $go . '?sort=' . $rows->name . '&order=ASC">UP</a>'; Code (markup):