SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 41 of 41
  1. #26
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, too right about No.3 I'll leave it for another posting
    1) - Thank you!
    2) - Thank you again!

  2. #27
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Cups,

    I'm also hoping to do the same for another area of my site. www.test.com/news/news-item-title -- how would this work, as it is using a different SQL table(not 'pages').
    Last edited by invision2; Jan 16, 2009 at 08:09.

  3. #28
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Why don't you post the fields in your table, and a sample row so we can look at the data.

  4. #29
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool. Here goes...

    The SQL Table name followed by the structure and example data...

    pages
    PHP Code:
    id filename title descr keys html subcat category

    1
    '0''Home Page''Home Page description''Keywords go here''Home Page test'0
    pagecat
    PHP Code:
    id url title

    1
    '''Home'
    2'accommodation''Accommodation'
    3'news''News' 
    news
    PHP Code:
    id title descr keys img1th1 img1th2 date user_id

    1
    'This is a test news item 3''Bla bla bla test 4''newsitem.jpg'''0x323030392d30312d3133
    I guess dream world would be if the result could be like www.test.com/news/news-title

    Please say if you need any more information. Really appreciate the help so far.

  5. #30
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    There are a couple of issues to address.

    1 using and storing "slugs"
    2 handling duplicates

    1 using and storing "slugs"

    Slug is a WP term for turning "This Thing Happened" into "this-thing-happened", the slug.

    a) You could store the slug in your database as you make each story.

    id | title | slug | etc ...
    ================
    1 | My title | my-title
    ---------------------

    Pros, easy to look up, easy to make your links

    Cons, what if you change the title of the page ?

    b) you could de-slug the string as it arrives

    ucwords( str_replace( "-", " ", $row['title'] ) )

    and then look up against the database, but then you've got to do the reverse when you make the links...

    2 handling duplicates

    How are you going to de-reference a slug or a string if you have two titles with the same name in your database?

    a) add some date-like "folder" /news/jan09/my-story, still relies on you not creating a dup for each month, but you have a by month retrieval system, might be a usability winner?

    b) disallow duplicates, mysql will enforce that for you

    Now heres the thing, if you only ever allow one title with a name, you don't need the id number anymore for each row, you can use the slug as the unique id.
    Shock!


    Now do you see where starting from your desired urls, armed with your new knowledge of mod_rewrite it can start to affect how think about your rdbms?

    I guess dream world would be if the result could be like www.test.com/news/news-title
    So work out which row in your table will news-title refers to, get the page working using the usual index.php?news=news-title - then make your .htaccess file.

  6. #31
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the reply Cups.
    Yes, I was going over it in my head last night and wondered whether it would make sense to use just ONE SQL table to hold all my content. I guess not.

    I have taken in what you said and just had a couple more queries.


    My main problem areas are the following:

    www.test.com/places-to-go/events
    I want most of the 'pages' on the places-to-go category to be mod_rewrited so they're pretty url's(places-to-go/shopping, places-to-go/eating-out etc.) and take data from the 'pages' table.
    However, I need a 'places-to-go/events' to do a MySQL query to list upcoming events. Does this mean storing some PHP in my 'html' column and using eval() or is there another workaround you can think of ?

    www.test.com/news/news-title
    I believe I will add a 'slug' column, and this slug is generated from the Title the user inserts. If it's a duplicate, I'll ask the user to enter a unique one.

    What do I need to do to my current index.php set up to get this working?
    Do I have to determine if it's ?category=news, then query the 'news' table instead of the 'pages' table?

    www.test.com/accommodation/cottage-name
    I have a separate SQL table for accommodation.
    Would I have to set up index.php to determine if it's ?category=accommodation then query the 'accommodation' table?
    Every 'title' value of the records in the accommodation table will be unique.


    I know this is a lot to digest and you've been incredibly helpful so far.
    If you can help a little more with this, I'd be eternally grateful.


    Thank you for any input.

  7. #32
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    In each case why don't you just opt for the simpler:

    www.test.com/accommodation/cottage-name

    rewrites to

    accommodation.php?title=cottage-name

  8. #33
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the reply Cups. That does seem a lot simpler.

    Does this mean I could then do the following:

    accommodation.php = www.test.com/accommodation
    accommodation.php?title=cottage-name = www.test.com/accommodation/cottage-name

    gallery.php = www.test.com/gallery/
    gallery.php?title=image-name = www.test.com/gallery/image-name

    news.php = www.test.com/news/ *
    news.php?title=news-title = www.test.com/news/news-title

    events.php = www.test.com/things-to-do/events/
    events.php?title=event-title = www.test.com/things-to-do/events/event-title

    Really sorry I have to ask like this, but sometimes I'm a little slow(especially with programming) and need it in black and white hehe. If you could provide an example for 'news.php' using the table structure above, it'd really help me.


    Really value your help with this, I'm trying to do new and better things.


    * can this be set up in the news.php script to list all my news items, like a 'normal' PHP script.



    Thank you

  9. #34
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    news.php = www.test.com/news/ *
    news.php?title=news-title = www.test.com/news/news-title

    To make those links rewrite use something similar to;

    ^news/?$ news.php?all=true
    ^news/([a-zA-z-]+)/? news.php?title=$1

  10. #35
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fantastic. Thanks again for the help, Cups. You're already a major legend in my book.

    OK, when I use that I get:
    www.test.com/news/?all=true -- is there anyway just to leave this as www.test.com/news/

    When I do:
    www.test.com/news/test-title - it works perfect - thanks very much!!!

    PHP Code:
    <?

    $all 
    $_GET['all'];
    $title $_GET['title'];

    if (
    $all == TRUE) {

    $sql "SELECT *
    FROM 
    news"
    ;

    echo 
    $sql;

    }

    else {

    $sql "SELECT * FROM news WHERE title = '$title'";

    echo 
    $sql;

    }

    include (
    '../include/sitetemplate.php');

    ?>
    I think the 'accommodation.php' works the exact same way as the news.php you helped me with, so no problems there.


    I know I'm asking a lot, but can you possibly explain how best to do this:

    events.php = www.test.com/things-to-do/events/
    events.php?title=event-title = www.test.com/things-to-do/events/event-title

    and this:

    gallery.php = www.test.com/about/gallery/
    gallery.php?title=image-name = www.test.com/about/gallery/image-name


    Many thanks once more.

  11. #36
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    OK, when I use that I get:
    www.test.com/news/?all=true -- is there anyway just to leave this as www.test.com/news/
    Dump the "all" just test for the absence of $_GET['title'], or just display "all" as the default behaviour, though I cant quite see how you have news/all=true in your link.
    PHP Code:
    <?

    if ( isset( $_GET['title'] ) && <! it passes some security test/frisk !> )  {

    $sql "SELECT * FROM news WHERE title = '$title'";

    }else{

    $sql "SELECT *
    FROM 
    news"
    ;

    }

    ?>
    I know I'm asking a lot, but can you possibly explain how best to do this:
    These are no different than the others I showed you, except they are one directory down, so it depends on where you put your .htaccess file whether or not you add the extra folder in your .htaccess rule. Try and work it out.

    The good thing with .htaccess and apache is that you don't have to keep stopping and starting the service.
    Last edited by Cups; Jan 18, 2009 at 10:19. Reason: forgot to close a tag

  12. #37
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for your help once more, Cups! It's invaluable.
    Although, I think I might be doing things the wrong way around. Correct me if I'm wrong.

    I have in my 'index.php' page:

    PHP Code:
    <?

    $category 
    $_GET['category'];
    $filename $_GET['filename'];

    if (
    $category == '') {
        
    $category '';
        
    $filename '0';
    }

    $sql "SELECT * FROM pages as p LEFT JOIN pagecat as c ON c.id = p.category WHERE  c.url = '$category' AND p.filename = '$filename' LIMIT 1";

    $res mysql_query($sql);

    $row mysql_fetch_array($res);

    $id $row['id'];

    include (
    '../include/template.inc');

    ?>
    Would it make sense then in my 'template.inc' file that I store all the content retrieved from the sql table(whether it just be the html column from my pages table, or a list of news items retrieved from the news table) in ONE variable, then just output that ONE variable in my 'template.inc' file:

    PHP Code:
    <html>
    <head>
    <title><? echo $row['2']; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>

    <body>

    <?

    // HTML
    echo '<br /><br />';
    echo 
    $onevariable';
    echo '
    <br /><br />';

    ?>

    </body>

    </html>
    ?

  13. #38
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Now you are wandering off into the topic of templates, something I am not at all au fait with.

    I think most people would agree that you have 2 templates, one for pages and one for news.

    What most people would also likely agree is that you store the data about a property in your database, not just a html string.

    Perhaps if you define a little more accurately what a "page" is, then you can focus in on what data will differ in each page.

    Take news as an example. News likely has;

    title (50 chars?)
    image
    intro (100 chars?)
    story (~2000 chars which may well contain html too)

    A webpage will typically have header, footer, meta data, sidebars, tickers, nav links - and then get the data it needs out of the database and display it neatly within all that stuff, depending on what kind of "webpage" you are making.

    Going back to this:
    PHP Code:
    $category $_GET['category'];
    $filename $_GET['filename'];

    if (
    $category == '') {
        
    $category '';
        
    $filename '0';

    Unless you are not showing me everything, you are seemingly failing to filter that incoming data, I know its coming from mod_rewrite, but that doesn't mean it can only come from mod_rewrite, you should be checking that contains only a-z etc.

    Read up on sql injection.

    You should be checking to see if category is not set, and if it is not set - shouldn't you be failing and sending this user away?

  14. #39
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Cups,

    Thanks again for the advice.

    The 'html string' I mentioned was storing what was retrieved from the SQL table. Whether it be for the 'html' column in my pages table, or a list of formatted news items from the news table.
    Yep, I think I'll put a bit more thought into how I do my 'template' side of things. But it looks like I'll have a few different templates the way things are going


    I plan to do a little more validation when retrieving the category and filename values. I will check for a-z, lower-case with a hyphen.
    If it's not set, I'll probably send them to a 404 page. I'll escape the data before it gets sent to the db too.

    Off Topic:

    'Cups' doesn't come from Underworld 'Cups' does it? Wow, when that synth kicks in around the 9-minute mark, brilliant stuff.

  15. #40
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    'Cups' doesn't come from Underworld 'Cups' does it? Wow, when that synth kicks in around the 9-minute mark, brilliant stuff.

    Got me.
    Beaucoup Fish album cover's my avatar. You're the first person ever to admit spotting it, gonna have to kill Cups off now

    Yes, I mentioned all the "security stuff" because, quite healthily IMO, ppl round here do tend jump on each other for not spelling it out frequently.

    It's worth spelling it out when you post code samples "Of course this does not include security checks, which i have left off in the interests of code brevity." kinda thing.

    Good luck with it, hope it works out.

  16. #41
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, I was convinced for a while it was the BF cover when I saw your posts but thought 'Nah, can't be' 'Winjer' too is a great track. I'll need to track it down again.
    Off Topic:

    If you haven't already, get the live dvd Everything, Everything, Cups sounds even better live.


    Yes, I should have made it a bit more obvious that I was doing more secure validation to the input, justwanted to keep the code to a minimum so not to put you off
    Totally agree on having a disclaimer with the code.


    Thanks, I may be back in a week or so with more queries


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •