March 20th, 2013, 02:48 PM
Pass variable value from one page to another
I'm trying to pass variable value from one php script to another. The answer is probably easy but I'm confused. So let's say that I have 4 company names (the values below are retrieved from the database)
Company A - View
Company B - View
Company C - View
Company D - View
The view button will take you to secondpage.php. If for example I click the first View button then in the secondpage.php I want to take the value of the first company which is ''Company A''. According to the selection I will retrieve some data from the database and print them.
Companies may be more or less than 4 with different names for different people (depends on your interests etc).
I tried to use while loop and inside the while loop I added a session but when I use the session to the second page it just gets one value (if i click either first view, or second or third blah blah... I'm getting the same value.. eg. Company A).
Hope it makes sense what I just said
Thanks in advance for your help
March 20th, 2013, 03:00 PM
why can't you simply use an URL parameter? Because that's the essence of it: You link to a page displaying information for a particular company.
The purpose of a session is to hold global data (like the language) for a whole site or at least a group of pages. So it hardly fits here.
March 20th, 2013, 03:04 PM
i have hundreds of companies in the database... I can't create so many php scripts for each company. That's what you said right?
So what I want is to have one page for all companies and I will print different staff according to each company (using mysql).
Is that possible?
March 20th, 2013, 03:47 PM
No, I'm talking about a URL parameter. You have a single script receiving the particular company through a URL parameter:
Originally Posted by shieldcy
March 20th, 2013, 04:12 PM
ooooh yeah now I get it.
Cool I'll give it a try! Thank you
Can I write something like that?
<a href="companypage.php?company=<?php $name ?>>
March 20th, 2013, 04:24 PM
to make sure $name doesn't break the URL.
Note that every character except "a", ..., "z", "A", ..., "Z", "0", ..., "9", "-", ".", "_", "~" will result in an ugly percent encoding. So either define a "URL friendly" company identifier, or use number IDs (which also allow fast database lookup).
March 20th, 2013, 04:27 PM
I see! appreciate ur help, thank you.
March 20th, 2013, 05:42 PM
edit: oops never mind, it was a really silly question :P sorryyy!
March 21st, 2013, 01:26 AM
Thanks for giving him a solution.Actually i have some problem with the same issue.Now i cleared with your solution.