[SOLVED] A linking problem in the form of a short story

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

[SOLVED] A linking problem in the form of a short story

Post by mohson »

I am currently experiencing the following problem

I have linked the 'organisation name' field stored in my people table to the 'web_url' field stored in my 'organisation table'

The reason for this is that I want to be able to click on the 'organisation name' and go directly to the organisations website.

To do this as described above I had to to a table join (left join) as shown below:

Code: Select all

$query = 	"SELECT 
		o.org_id,o.web_url,
		p.person_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact,
		p.datecontactagain,p.notes,p.email, 

		DATE_FORMAT(dateoflastcontact, '%d/%m/%y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%d/%m/%y') 
		AS datecontactagain 

		FROM people p LEFT JOIN organisations o
     		ON o.org_ID = p.person_id		
		ORDER BY firstname";
ps. o.org_id and p.person_id are the same values

I then created the link using the following

Code: Select all

'<a href='.$row->web_url.'>'.$row->organisation . '</a></td><td>'.
Simple stuff so far right??

Yes!! Well it is - and where ever the o.org_id matched the p.person_id the web_url link is stored............... THE PROBLEM is this:

the web_url is preceeded by the url of the current page WHY IS THIS??

for example if the 'web_url' is http://www.hotmail.com and the current page is

http://editweb.soi.city.ac.uk/organisat ... people.htm

then the following will occur:
http://editweb.soi.city.ac.uk/organisat ... otmail.com

The solution maybe very simple but its been bugging me for a week now.. any ideas anyone??
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

that is how a relative url works.....

either make sture to always store the protocol... as in store http://www.example.com in your database....

or add it yourself when you output it <a href="http://" . $row->url (imho this is not a good solution).
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Problem sorted - Thank you Tim your a star
Post Reply