russe11 Posted January 6, 2007 Share Posted January 6, 2007 I have successfully and hardly made my url from [b]articles2.php?title=Low%20calorie%20diet%20plan&id=1[/b]to[b]/articles2/1-low-calorie-diet-plan.htm[/b]After many days figuring out how to do the mod_rewrite, now i can not figure out how to fix my links(script) to point to the newly created mod_rewrite url.My links still points to : [b]articles2.php?title=low calorie diet plan&id=1[/b]Question: How can i dinamicaly point my articles database links to the new friendly url made with mod_rewrite?My code:[code]<?phpinclude '../database.php';// if no id is specified, list the available articlesif(!isset($_GET['title'])){ $self = $_SERVER['PHP_SELF']; $query = "SELECT title, id FROM news ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list $newstext = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($title, $id) = $row; $newstext .= "<li><a href=\"$self?title=$title&id=$id\">$title</a></li>\r\n"; } $newstext .= '</ol>'; $title = 'Diet Plan Articles';} else { // get the article info from database $query = "SELECT title, newstext FROM news WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $newstext = $row['newstext'];}mysql_close();[/code]Thank you in advance for any insight on this solution that i am after! :) Quote Link to comment https://forums.phpfreaks.com/topic/33146-php-side-from-mod_rewrite/ Share on other sites More sharing options...
wildteen88 Posted January 7, 2007 Share Posted January 7, 2007 After this:[code=php:0]list($title, $id) = $row;[/code]Add this:[code=php:0]$titleURL = str_replace(' ', '-', $title);[/code]Then change this code:[code=php:0]$newstext .= "<li><a href=\"$self?title=$title&id=$id\">$title</a></li>\r\n";[/code]to this:[code=php:0]$newstext .= "<li><a href=\"{$self}{$id}-{$titleURL}.htm\">$title</a></li>\r\n";[/code]That should be right. Test it and see Quote Link to comment https://forums.phpfreaks.com/topic/33146-php-side-from-mod_rewrite/#findComment-154993 Share on other sites More sharing options...
russe11 Posted January 11, 2007 Author Share Posted January 11, 2007 Thank you very much for your help. I have been working and suffering with mod rewrite and php linking structure- i am an official newbie! - , but your reply did give me lots of light in the tunnel, and i was able to figure out how to do it! Thank you once again for your help. Phpfreaks rules! :o Quote Link to comment https://forums.phpfreaks.com/topic/33146-php-side-from-mod_rewrite/#findComment-158006 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.