Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-26-2011, 12:32 AM   PM User | #1
TurkzZ
New Coder

 
Join Date: Mar 2011
Posts: 33
Thanks: 9
Thanked 0 Times in 0 Posts
TurkzZ is an unknown quantity at this point
How to change url structure?

Ok this is my site http://www.turkish-football.com/ , and when i click on a link it currently comes up as:

http://www.turkish-football.com/news_read.php?id=315

now instead of the whole ID thing id rather the name of the article came up, however when i try to do it, it comes up as egemen%20Korkmaz and so on, and doesnt work

how do i change the URL structure so the article name comes up and not some ID, i hear this is good for SEO as well

thanks
TurkzZ is offline   Reply With Quote
Old 05-26-2011, 12:39 AM   PM User | #2
Puppet Master
New Coder

 
Join Date: Nov 2010
Location: California
Posts: 42
Thanks: 6
Thanked 2 Times in 2 Posts
Puppet Master is an unknown quantity at this point
You can make the query get the title rather than the id. You can also use a URL rewrite condition, the that's with an apache script I think.
__________________
Puppet Master + Programming = Eternal Bliss
Puppet Master is offline   Reply With Quote
Old 05-26-2011, 01:03 AM   PM User | #3
TurkzZ
New Coder

 
Join Date: Mar 2011
Posts: 33
Thanks: 9
Thanked 0 Times in 0 Posts
TurkzZ is an unknown quantity at this point
i tried getting the query to get the title but it came up with the %20 between the words and didnt work, ill give another shot now, what's the URL rewite condition? would that mean that there would be two links to each article?
TurkzZ is offline   Reply With Quote
Old 05-26-2011, 01:08 AM   PM User | #4
TurkzZ
New Coder

 
Join Date: Mar 2011
Posts: 33
Thanks: 9
Thanked 0 Times in 0 Posts
TurkzZ is an unknown quantity at this point
currently the query goes:

on the home page click each news has a link as the following:
PHP Code:
<a href='news_read.php?id=$row[id]'> <img src=admin/mainnewsimg/".$row['photo'] ." alt='$title' width='125' height='85'> </a
and on the news page where it displays the news:

PHP Code:
<?php
if(isset($_POST['submit']))
{
}
    elseif(isset(
$_GET['id']))
    {    
    
$result mysql_query("SELECT * FROM news WHERE id='$_GET[id]' ",$connect);

        while(
$row mysql_fetch_assoc($result))
        {
            
$title stripslashes($row["title"]);
            
$summary stripslashes($row["summary"]);
            
$body stripslashes(nl2br($row["body"]));
            
$date $row['date'];
            
$pic $row['photo'];
            
$id $row['id'];
            
$date date("d M Y");
}
}
?>
and to display the news:
PHP Code:
    <?php
    
//display data
        

        
echo "<h1 class='headline_header_font'>".$title."</h1>";
        echo 
"<h4 class='date'>$date</h4><hr>";
        echo 
"<img src=admin/mainnewsimg/$pic alt='$summary' width='275' height='155' class='news_img'>";  
        echo 
"<p>$body</p>";
        echo 
"<br>";
    
?>
TurkzZ is offline   Reply With Quote
Old 05-26-2011, 04:29 PM   PM User | #5
TheMachineWare
New Coder

 
Join Date: Mar 2011
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
TheMachineWare is an unknown quantity at this point
The way I worked around this is to replace the spaces in the title with a underscore. The %20 is a space.

I currently use the rewrite on my site and then also use php to decode the url and transform my links from a easily readable text link to ?=id=somevalue.

This is a good way I have found to work with this. the underscore is a great for this purpose.

Feel free to contact me and I can help you out more.
TheMachineWare is offline   Reply With Quote
Old 05-26-2011, 06:16 PM   PM User | #6
TurkzZ
New Coder

 
Join Date: Mar 2011
Posts: 33
Thanks: 9
Thanked 0 Times in 0 Posts
TurkzZ is an unknown quantity at this point
hmmm even in the url if i replace the %20 with _ it doesn't pull the data from DB, if poss could you post an example of the code used on a link so i can compare,
TurkzZ is offline   Reply With Quote
Old 05-26-2011, 09:56 PM   PM User | #7
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Quote:
Originally Posted by TurkzZ View Post
hmmm even in the url if i replace the %20 with _ it doesn't pull the data from DB, if poss could you post an example of the code used on a link so i can compare,
You need to return the underscore to a space before you make your query against the DB.
MattF is offline   Reply With Quote
Old 05-26-2011, 11:20 PM   PM User | #8
TurkzZ
New Coder

 
Join Date: Mar 2011
Posts: 33
Thanks: 9
Thanked 0 Times in 0 Posts
TurkzZ is an unknown quantity at this point
ok this whole url structure has confused me, am I meant to change something in the .htaccess file lol, im stumped by this one
TurkzZ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:50 PM.


Advertisement
Log in to turn off these ads.