PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 17th, 2012, 10:44 PM
John Romaine John Romaine is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 John Romaine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 8 sec
Reputation 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");
}

Reply With Quote
  #2  
Old December 18th, 2012, 05:25 AM
John Romaine John Romaine is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 John Romaine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 8 sec
Reputation Power: 0
Anyone?

Reply With Quote
  #3  
Old December 18th, 2012, 12:25 PM
msteudel's Avatar
msteudel msteudel is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712 msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
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.

Reply With Quote
  #4  
Old December 18th, 2012, 04:13 PM
John Romaine John Romaine is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 John Romaine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 8 sec
Reputation 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>

Reply With Quote
  #5  
Old December 18th, 2012, 05:06 PM
msteudel's Avatar
msteudel msteudel is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712 msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level)msteudel User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
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>

Reply With Quote
  #6  
Old December 18th, 2012, 05:16 PM
John Romaine John Romaine is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 John Romaine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 8 sec
Reputation 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?

Reply With Quote
  #7  
Old December 18th, 2012, 05:26 PM
John Romaine John Romaine is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 John Romaine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 8 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Permalink issue - need some help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap