Hello all.
I am designing a web site in php. I am working on creating a page that takes user input, searches a SQL db, and returns the result. I would like to then create a unique link for each primary key that is returned. So that by clicking this link, the user will be taken to a page that displays all info regarding that entry. My problem is when I get the results back. I have the information, can post it to the page, and create the link out of it (the <a href=></a> tags with info) , I just can't seem to make a link based on that. The only information I need to get to the next page, call it the info page, would be which primary was clicked -- I don't mind making the query a second time once I get to the info page either. So basically out of a list the user sees as results from their query, I want to know which one the user has selected and then go to the info page.
I am pretty sure I could do this with a form and radio buttons, and then save the result to the _SESSION array, but I would rather stay away from the use of radio buttons. I bring it up only to help clarify what I am trying to accomplish.
I do appoligize for posting, but I have searched a lot for this answer, and I can't imagine its more then a few lines of code either. I appreciate any responses or hints to the right direction I can get.
soloslinger
creating links from sql query results
Moderator: General Moderators
-
soloslinger
- Forum Newbie
- Posts: 2
- Joined: Fri Mar 16, 2007 6:07 pm
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
The link should be in the form http://mysite.com/view.php?id={RESULT ID}. The id variable can be accessed by $_GET -- you will have to call a second query to get the row data for that ID.
-
soloslinger
- Forum Newbie
- Posts: 2
- Joined: Fri Mar 16, 2007 6:07 pm
Thank you for the response. I kinda stumbled upon that as the only really viable solution as well. I guess my biggest concern then is how is that method considered as far as good php practices? Heck, is there a handy website for a place to study on good php coding practices?
Also, what deliminates multiple items in the url so $_GET can access them? By going with this solution I am manually putting these up in the URL, and if the case arises that I want to put more info in the url, I'd like to know.
soloslinger
Also, what deliminates multiple items in the url so $_GET can access them? By going with this solution I am manually putting these up in the URL, and if the case arises that I want to put more info in the url, I'd like to know.
soloslinger
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
&soloslinger wrote:Thank you for the response. I kinda stumbled upon that as the only really viable solution as well. I guess my biggest concern then is how is that method considered as far as good php practices? Heck, is there a handy website for a place to study on good php coding practices?
Also, what deliminates multiple items in the url so $_GET can access them?
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
This is de facto standard for transmitting non-sensitive information from page to page, especially if the page needs to be accessed directly by URL (e.g., from a bookmark or link from another site). Be sure that the register_globals globals directive is disabled and that you do not use $_SERVER['PHP_SELF'] in anchored links or for header redirection.soloslinger wrote:I guess my biggest concern then is how is that method considered as far as good php practices? Heck, is there a handy website for a place to study on good php coding practices?
As for learning good practices, this forum is a good place to start -- check out the "Useful Posts" sticky at the top of this forum.