Page 1 of 1

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

Posted: Tue Feb 15, 2005 5:50 am
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??

Posted: Tue Feb 15, 2005 5:58 am
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).

Posted: Tue Feb 15, 2005 6:20 am
by mohson
Problem sorted - Thank you Tim your a star