Results 1 to 4 of 4
March 20th, 2007, 01:43 PM #1Need php code work
I have successfully used the script in this thread and converted one of my sites over to a database/datafeed driven site.
I need help in modifying the above referenced script to:
- Make a copy of the 'Name' field
- Parse the new name field and replace any 'spaces' with a 'hyphen'
- save this new field as a seperate column in the table
This is so I can use mod/rewrite in the url's.
Please reply here, or privately at ric at signsbyric dot com with your price.
March 21st, 2007, 03:22 AM #2
Ric, than can be handled in your display script.
Somewhere after your call from the DB and before you print the results....
Replace yourfield with the column/variable pulled from the DB...
$yourfield = str_replace(" ", "-", $yourfield);
$yourfield = strtolower(str_replace(" ", "-", $yourfield));
March 21st, 2007, 07:53 AM #3
I will give that a try this afternoon. Since I am also using the Name field on the display page below the thumbnail, I would assume that I would use this to leave the original Name field alone, and create a new variable based off of it:
$NameURL = strtolower(str_replace(" ", "-", $Name));
March 21st, 2007, 08:03 AM #4
Yup, that will work. But you don't HAVE to create the new variable (it might be nice for convenience if you're using the $NameURL in multiple spots), you can just use that block of code in any instance where you use $NameURL.
For example, if your page looks something like this:
$NameURL = strtolower(str_replace(" ","-", $Name));
you could eliminate the second variable all together like so:
echo strtolower(str_replace(" ","-", $Name));
No change to the variable $Name has taken place. This works in SQL statements as well so that
$query = "INSERT INTO `sometable` (`name1`, `name2`) VALUES ('$Name', '$NameURL')";
would look like
$query = "INSERT INTO `sometable` (`name1`, `name2`) VALUES ('$Name', '" . strtolower(str_replace(" ","-", $Name)) . "')";
Like I said, creating a second variable might be nice for the sake of readability (and especially useful if you're using $NameURL multiple times throughout the script), but it's not necessary. If you're only using the $NameURL once, I probably wouldn't create the new variable, but use the functions Ric pointed out to you on the spot that I wanted that value returned.
I hope that makes sense...
Last edited by cbsturg; March 21st, 2007 at 08:04 AM. Reason: small typos...Chris Sturgill
"All my life I've had one dream, to achieve my many goals." - H. Simpson
By spiderninja in forum Midnight Cafe'Replies: 0Last Post: January 31st, 2007, 11:12 PM
By Dan76 in forum Programming / Datafeeds / ToolsReplies: 10Last Post: March 18th, 2006, 12:35 PM
By tvcrazyman in forum GoldenCANReplies: 4Last Post: January 19th, 2006, 05:22 PM