The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Permalink issue - need some help
Discuss Permalink issue - need some help in the PHP Development forum on Dev Shed. Permalink issue - need some help PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 17th, 2012, 10:44 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
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");
}
|

December 18th, 2012, 05:25 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
Time spent in forums: 2 h 4 m 8 sec
Reputation Power: 0
|
|
|
Anyone?
|

December 18th, 2012, 12:25 PM
|
 |
Contributing User
|
|
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712
 
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.
|

December 18th, 2012, 04:13 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
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>
|

December 18th, 2012, 05:06 PM
|
 |
Contributing User
|
|
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712
 
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>
|

December 18th, 2012, 05:16 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
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?
|

December 18th, 2012, 05:26 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 5
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|