Link to home
Start Free TrialLog in
Avatar of fcruz5
fcruz5Flag for United States of America

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.
<?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 />';
 
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Matthew Kelly
Matthew Kelly
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fcruz5

ASKER

Hi matthewstevenkelly,

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.




Avatar of fcruz5

ASKER

Nevermind, I see the problem. I just needed to add a dash

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 />';
 
 

Open in new window