Are you looking to change the spaces to dashes when you insert the data into the database, or just when displaying the data after retrieving it from the database? (In either case, it would help to also tell us what DBMS you are using and what programming language.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
it really has nothing to do with what programming language you use.
It does if you want to do the search/replace within the program instead of within the query. I'm not saying either way is "better", just that there are two ways to approach it. (You might want the script to support several DBMS's so don't want to depend on a query function that's not part of standard SQL, perhaps?)
actually, a string replace function is part of the standard.
and even if you wanted to search outside of the database (i will never know why you'd want to do that...) you can still search in these terms, and you'd have to convert the spaces in your search w/ dashes - but for some reason I don't see that being any more useful.
I need to do it that way so that I can display the TITLE as a link on the site without dashes. But the link to the actual article needs to have dashes in it when displayed in the address bar since spaces are not allowed in the URL.
Your way may work but since I am integrating another app I need to go around their code. I dont want to add anymore fields to the other app since it is much larger than the entry page that I am creating for it.
Test Article <--- TITLE as shown in table
Also I am not ordering by article number, it is by Most Hits.
I am not sure exactly why the original code was written to display this way, all I can think of is to make it SE friendly and to allow for duplicates of article titles.
at the bare minimum you can just select both columns, you actually don't get a performance hit. typical sql functions run faster, since they can deal with the raw data. I'm not sure how you'll see it between MySQL and php computing it
select other_columns, REPLACE(`article_title`,' ','-') article_title_dash, article_title FROM your_table;
and you would refer to the column article_title_dash.
Don't misjudge SQL by any means - you can write an entire application with just sql statements, using a server side language to display the output and parse passed parameters. Oracle's PL/SQL can actually take the place of a server side language - it's a derivative of Perl that can interact with a database directly.