fcruz5
asked on
PHP MySQL query link?
Hi,
The following query will generate the correct data, but the links are not right. Currently they are generated like this:
http://mysite.com/2008-11-14 16:49:08/A beautiful day
Is there a way to display them like this?
http://mysite.com/2008/11/14/A- beautiful-day
The date would be displayed with a forward slash in between and without the time. And the title would be displayed with hypens in between.
The following query will generate the correct data, but the links are not right. Currently they are generated like this:
http://mysite.com/2008-11-14 16:49:08/A beautiful day
Is there a way to display them like this?
http://mysite.com/2008/11/14/A- beautiful-day
The date would be displayed with a forward slash in between and without the time. And the title would be displayed with hypens in between.
<?php
include ('db.php');
$query = "SELECT date, title FROM story";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo '<a href="http://mysite.com/' . $row['date'] . '/' . $row['title'] . '">' . $row['title'] . '</a><br />';
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nevermind, I see the problem. I just needed to add a dash
substr(str_replace("-","/" ,
Thanks!
substr(str_replace("-","/"
Thanks!
echo '<a href="http://mysite.com/' . substr(str_replace("-","/",$row['date']),0,10) . '/' . str_replace(" ","-",$row['title']) . '">' . $row['title'] . '</a><br />';
ASKER
I tried your solution, but I am getting a "-" in the date section like this:
http://mysite.com/2008-11-14/A- beautiful-day
It should look like this:
http://mysite.com/2008/11/14/A- beautiful-day
Everything else is right.