Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Search Engine Friendly PHP URLS

../archive.php?id=4 = BAD

     

alcheme

9:41 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



Hello,

Currently, I can create archived articles list on a page called archive_list.php. Each article can be clicked on and it opens in articles.php.

The extension looks like: ../articles.php?id=4

I want to be able to open the article with the 'name' of the article or name of the 'author' instead of using the ID number from the database table. However, '../article.php?title=The Day Blah Blah' does not work. It has spaces too...

Can anyone help? Is there a way to replace the spaces with underscores so it will work?

@@@@@@@@@@@@@@@@@@@@@@@
HERE is the code from ../article_list.php:
@@@@@@@@@@@@@@@@@@@@@@@

$sql = mysql_query("SELECT id, author, title FROM articles ORDER BY id ASC");

if ($myrow = mysql_fetch_array($sql)){

$id=$myrow["id"];
$insert_date=$myrow["insert_date"];
$author=$myrow["author"];
$title=$myrow["title"];

echo "<table class=table_general cellpadding=0 cellspacing=5>";

do {

printf("<tr bgcolor=#55556F><td valign=top width=150><b><a href=%s?id=%s>%s</a></b></td><td><div align=justify>%s ... <br><br><font color=#FFFF00>[<b><a href=%s?id=%s title=%s>READ FULL DEFINITION</a></b>]</font></div></td></tr>\n", "article.php", $myrow["id"], $myrow["title"], $myrow["author"], "article.php", $myrow["id"], $myrow["title"]);

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Suggestions?

~Shane

jonrichd

10:50 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



I'm not a great php/sql wizard, so you will have to figure out the coding yourself, but what you need to do is replace each space in your title with '%20'

So, ../article.php?title=The Day Blah Blah becomes
../article.php?title=The%20Day%20Blah%20Blah

That gives you a continuous string for your title parameter, and since %20 is the hex code for space, it means the same thing as the space does.

maccas

11:26 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



No php wizz myself either, but couldn't you also use str_replace

../articles.php?id=some-authors-name

$author=$myrow["author"];
$author=str_replace("-"," ",$author);

alcheme

3:52 am on Jul 4, 2005 (gmt 0)

10+ Year Member



Hi Maccas,

I tried this:

$author_strip = array("");
$author=str_replace($author_strip,"-",$author);

but only the first name comes up and the rest of the details from the datavase don't appear after the authors name.

i.e. [website.com...]

The middle and last name do not appear.

And ideas anyone?

~Shane

copongcopong

4:36 am on Jul 4, 2005 (gmt 0)

10+ Year Member



here is a tip ...

if your main intention is to have search engine friendly url, you simply try to do it in this way

article.php?title=some+title+here-355

355 would be the article_id in your database. What you need to do then is to parse the value of title to be able to get the id 355.

You can do str_replace and encode the title in a "-" dash separated manner then use explode() to change them in an array then array_reverse(), ... then array[0] would be the id (355) then use it in your sql statement to get the article

btw, urlencode() decode is also handy when dealing with query strings

alcheme

6:20 am on Jul 4, 2005 (gmt 0)

10+ Year Member



Sorry that went over my head a bit. Can you show me what that looks like?