views:

35

answers:

1

Hi fellows! I'll try to ask this correctly. This has got me licked.

I have a script online that will bring up items according to a search on let's say, page1.php. The results come from a table called items. The results list has links to the items that look like this: a href=\"/" . "boats/$name/" . "$p". $line["PID"]. ".html\"

In another table in the same database, there is a table named "morphlinks" with two fields in it named elink and ulink. elink has id numbers which correspond to id numbers in the table named "items".

CREATE TABLE IF NOT EXISTS morphlinks ( 
  elink varchar(128) NOT NULL default '',
  ulink varchar(255) NOT NULL default '', 
  PRIMARY KEY (elink) 
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO morphlinks (elink, ulink) VALUES ('12345', 'canoes/Blue-Canoes/Bob-Morris/');

What I'm hoping to do is to add what's in the corresponding row in "morphlinks" to the url where you see "boats/$name/". So the list of items with urls to display them will look like this on a php page: a href=www.domain.com/canoes/Blue-Canoes/Bob-Morris/12345.html where canoes/Blue-Canoes/Bob-Morris/ is what's in the "morphlinks" table and 12345 is the PID number.

It all works fine except for the canoes/Blue-Canoes/Bob-Morris/ part. I can't figure out how to get that part into the url. The url works fine and goes to the same item whether it's in there or not but we want it in there for seo purposes. We will manually populate the "morphlinks" table occasionally.

Thanks, Douglas

A: 

Your question wasnt exatly clear on the code iterating over the rows but i assume $line is the mysql row as an assoc array.. im not sure where $name is coming from so im going to ignore that for now... if you want to update your question with more info i can give you something more exact, but the following is a general way to go about it...

First modify the query to join the morphlinks to the items.. i assume pid == elink

SELECT items.*, ml.ulink from items
LEFT JOIN morphlinks ml ON (items.pid = ml.elink)

So now in your rsults array you chould have a $line['elink'].

from here its easy (im goign to use sprintf for sanity!):

sprintf(
   'a href="/%s%s%s.html"', 
   (!empty($line['elink']) ? $line['elink'] : "boats/$name/"), 
   $p,
   $line['PID']
)
prodigitalson
Thanks for the answer. I should have been more clear. $name corresponds to ulink in the "morphlinks" table which has the list of names or partial paths. (canoes/Blue-Canoes/Bob-Morris/)
Fisherman
so `$name` is a primary key then? Also is `$line` the actual array representation of the row? also what is `$p` Can you post the schema (`show create table morphlinks; show create table items;`)?
prodigitalson
I should have been more clear. $name corresponds to the ulink field in morphlinks which has the partial paths (canoes/Blue-Canoes/Bob-Morris/) in it. The resulting links won't redirect the page but will be listed on the resulting page. A search will direct the user to the page with this code in it and then they will click on the links that this will produce to view the items. So when this items.php page loads, it lists the links which I am trying to fit the partial paths into.
Fisherman
Sorry, I hit enter before I finished the first comment.
Fisherman
-- Table structure for table `morphlinks`--CREATE TABLE IF NOT EXISTS `morphlinks` ( `elink` varchar(128) NOT NULL default '', `ulink` varchar(255) NOT NULL default '', PRIMARY KEY (`elink`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;---- Dumping data for table `morphlinks`--INSERT INTO `morphlinks` (`elink`, `ulink`) VALUES('12345', 'canoes/Blue-Canoes/Bob-Morris/');
Fisherman
@fisherman: and what about `items`?
prodigitalson
Items is the other table and among other things it has the PID number and name.<p>The reason we are doing this is that the $name (in items) of the items aren't always the prettiest or the way we want them to show up so we have a spreadsheet with all of the names and another column that lists them like we like them. Then we stick all of the other stuff before it like cat and sub-cat with slashes between and if this works, my wife'll be real happy. LOL ;)
Fisherman
How do I send you a private message or an e-mail? I'd like to show you what I don't want to paste out in public if that's alright.
Fisherman
prodigitalson