homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Create clickable URLS from mysql php result on same page?
MYSQL results from php turn into unique link

Msg#: 4690079 posted 11:20 am on Jul 23, 2014 (gmt 0)

I have a search page, that returns mysql query like so :

echo "<a onclick='function1();function2();function3()'>",$row['compn'],"</a>";
echo "<form><input type='text' id='tester' value='",$row['compuid'],"' hidden='hidden'></input></form>";

Nothing on my page opens a new page or loads a new one. Everything basically resides on the same page. The results are displayed in another overlay :

<a onclick="function1();function2();function3()"></a>
<form><input id="tester" type="text" hidden="hidden" value="abcdefg"></input></form>

<a onclick="function1();function2();function3()"></a>
<form><input id="tester" type="text" hidden="hidden" value="mnopqrs"></input></form>

As you can see above, it kind of works BUT not like I want it to be :
If clicked on the top "link", it will load
id="tester" into document.getElementById("tester").value; and then display abcdefg. If I click on the bottom link, it will again load tester and display abcdefg. HOW do I get the code or the php to load a dynamic attribute or something, so that if I click the below link, it will actually display mnopqrs ?

Note: When a result link is clicked, it should display more details on an overlay by reading off from the php. For example :

link 1 = Peter, LAW
link 2 = Kate, JOURNALISM

(click on link 1:)
Peter, BIO : Peter has been studying LAW for more than 2 years,
Peter was born on 24/05/1992. Picture of Peter

(click on link 2:)
Kate, BIO : Kate has been studying ...



WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

Msg#: 4690079 posted 2:36 pm on Jul 23, 2014 (gmt 0)

Your problem would seem to be that you have more than one element with the same ID ie. "tester" (this is invalid HTML). When you
getElementById("tester") you are (probably) always going to get the first element with this ID ie. "abcdefg" in your example.

When you generate your HTML from PHP you should be outputting "tester1", "tester2", etc. (or something like that.) You can assign a similar/corresponding ID to your links eg. "link-1", "link-2", etc. so you can easily work out which "testerN" to lookup.


You should really be assigning event listeners using DOM methods, rather than in the HTML onclick attribute directly. When you call functions from the onclick attribute they are simply called in the global scope - there is no event object - you don't know on which element the event occurred.

Also, INPUT elements do not have a closing tag. And INPUT elements don't need to be enclosed in a FORM, unless this is being submitted (or maybe you don't have any other container?).

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved