Forum Moderators: coopster
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
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.
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
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