phpBeginner06 Posted October 15, 2006 Share Posted October 15, 2006 Is there any way to sort a data table column that has hyperlinks in it; in ascending order? I tried to use "ORDER BY make ASC" (where "make" was the name of the column). The results where that the text in column is not being sorted by ascending; but the hyperlinks tag's text is being sorted by ascending. How can I make the text sort by ascending and exlude the hyperlink tag's text from being sorted by ascending? Quote Link to comment https://forums.phpfreaks.com/topic/24018-how-to-sort-columns-with-hyperlinks/ Share on other sites More sharing options...
MCP Posted October 16, 2006 Share Posted October 16, 2006 assuming your links are like this:[code]<a href="http://www.google.com">Google</a>[/code]then you can use a combination of charindex and substr to first locate the position of the first ">" (I don't think that ">" is a valid URL character), and the take everything after that and sort on that. You wouldn't need to strip the "</a>", since it's pretty will immaterial (at the end and always the same).so something like:order by substr(make,charindex(">",make),len(make)) -- this is untested and from memory, and most assuredly syntactically wrong Quote Link to comment https://forums.phpfreaks.com/topic/24018-how-to-sort-columns-with-hyperlinks/#findComment-109230 Share on other sites More sharing options...
phpBeginner06 Posted October 16, 2006 Author Share Posted October 16, 2006 Thanks for the quick reply MCP. I found a way to accomplish what I was trying to do. I added two new data table columns; the first contains the opening hyperlink's tag: [code]<a href="http://www.google.com">[/code] and the second contains the closing hyperlink's tag: [code]</a>[/code] I gave the columns a instance/variable name of "openLink" (for the opening of hyperlink's tag) and "closeLink" (for the closing of hyperlink's tag). Then in my HTML/PHP, I used an echo to display all three instance/variable names.Example: echo "$openLink $make $closeLink"; // this creates the hyperlinkThis may not be the correct way to do this; but it worked great for me. Now all the text in my data table's column sorts in ascending order and the hyperlink tag's text is now excluded from the sorting process. Quote Link to comment https://forums.phpfreaks.com/topic/24018-how-to-sort-columns-with-hyperlinks/#findComment-109347 Share on other sites More sharing options...
argoSquirrel Posted October 16, 2006 Share Posted October 16, 2006 Correct me if I am of base, but couldn't you just store the hyperlink itself? I see no need to store <a href=" on every single one when you could just echo it from php. That should solve the sort and clean up a little redundancy. Quote Link to comment https://forums.phpfreaks.com/topic/24018-how-to-sort-columns-with-hyperlinks/#findComment-109607 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.