#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Permalink issue - need some help


    Hi everyone,
    I'm an old school asp programmer, so in terms of PHP I'm totally lost. I'm running custom blog software that I've just recently made some changes to, and now it seems I've hit the wall.

    I have the following snippet of code that I need to point at certain pages, but I'm totally lost.

    <a href="/<?php echo permalink($rstDBEdit);?>" title="<?php echo $rstDBEdit["podcast_title"];?>"><?php echo $rstDBEdit["podcast_title"];?></a>

    ...and here's the function that calls the permalink stuff.

    function permalink($a)
    {
    // need to get category
    $r=query_wrapper("SELECT * FROM blog_category WHERE cat_ID = ?",$a["article_category"]);
    $c=mysql_fetch_assoc($r);
    if(!$c)$c=array("cat_category"=>"-");

    $c=preg_replace('@[^\w\s]@si','-',$c["cat_category"]);
    $c=preg_replace('@\s+@si','-',$c);

    $p=preg_replace('@[^\w\s]@si','',$a['article_title']);
    $p=preg_replace('@\s+@si','-',$p);
    return strtolower("$c/$a[article_ID]/$p.php");
    }

    The problem is, I've just added podcasts to my site, and now I would like to use the same function to call entries to the podcast table within the database.

    I'm completely lost, how do I do this?

    Could I do a permalink ($b) or something?????


    function permalink($b)
    {
    // need to get category
    $r=query_wrapper("SELECT * FROM blog_category WHERE cat_ID = ?",$a["podcast_category"]);
    $c=mysql_fetch_assoc($r);
    if(!$c)$c=array("cat_category"=>"-");

    $c=preg_replace('@[^\w\s]@si','-',$c["cat_category"]);
    $c=preg_replace('@\s+@si','-',$c);

    $p=preg_replace('@[^\w\s]@si','',$a['podcast_title']);
    $p=preg_replace('@\s+@si','-',$p);
    return strtolower("$c/$a[podcast_ID]/$p.php");
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Anyone?
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    12
    There' a lot of info that I'm not really understanding, but from what you've written perhaps you could alter the permalink function like so:

    PHP Code:
    function permalink($b$type null )
    {
        switch( 
    $type ) {
            case 
    "podcast":
                
    $cat_id $a['podcast_category'];
                
    $cat_id_field 'podcast_category';
                
    $title_field 'podcast_title';
                
    $id_field 'podcast_ID';
                break;
            default:
                
    $cat_id $a['cat_category'];
                
    $cat_id_field 'cat_category';
                
    $title_field 'article_title';
                
    $id_field 'article_ID';
                break;
        }

    // need to get category
    $r=query_wrapper("SELECT * FROM blog_category WHERE cat_ID = ?",$cat_id);
    $c=mysql_fetch_assoc($r);
    if(!
    $c)$c=array("cat_category"=>"-");

    $c=preg_replace('@[^\w\s]@si','-',$c[$cat_id_field]);
    $c=preg_replace('@\s+@si','-',$c);

    $p=preg_replace('@[^\w\s]@si','',$a[$title_field]);
    $p=preg_replace('@\s+@si','-',$p);
    return 
    strtolower("$c/$a[$id_field]/$p.php");

    Also what blog software are you using? I would guess that they have some built in way to do this besides hacking this function ... so you might go to the docs and see if you can figure out a kosher way to do this.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Thank you so much for responding, I really appreciate it. Unfortunately however that didn't work, and I'm at a bit of a loss on how to correct it.

    It certainly *looks* close.

    How can I clarify further to make it easier for you?

    The software is custom made (my old programmer helped with it) but unfortunately he's not available.


    Your script appears to include a case statement, where in this URL would I define the case that needs to be called?

    Podcast link.

    Code:
    <a href="/<?php echo permalink($rstDBEdit);?>" title="<?php echo $rstDBEdit["podcast_title"];?>"><?php echo $rstDBEdit["podcast_title"];?></a>
    Blog link.

    Code:
    <a href="/<?php echo permalink($rstDBEdit);?>" title="<?php echo $rstDBEdit["article_title"];?>"><?php echo $rstDBEdit["article_title"];?></a>
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    12
    For blog links you shouldn't have to change anything, for your podcasts you'd just add the second parameter:

    Code:
    <a href="/<?php echo permalink($rstDBEdit, 'podcast');?>" title="<?php echo $rstDBEdit["podcast_title"];?>"><?php echo $rstDBEdit["podcast_title"];?></a>
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    Cool.

    Okay, getting closer.

    I'm getting the following URL when I mouse over the podcast link...

    http://localhost/14/9/test.php (working locally)

    It appears its pulling cat_id_field (14) instead of the actual category name, which is 'cat_category' within the DB.

    It *should* read something like ....

    http://localhost/conversions/9/test.php

    The blog link errors out?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0
    I should note that both podcasts and blogs use the same category table in the DB.

    Its called 'blog_category'

    Not sure if this helps any, but heres a screenshot of that table.

    recipeschickenbreast.com/images/db.gif

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo