|
|||||
|
|
#1 |
|
|
that page, without using Forms? Example: a webpage has the following words: <A HREF="result.php">apple</A> <A HREF="result.php">banana</A> <A HREF="result.php">orange</A> <A HREF="result.php">grape</A> <A HREF="result.php">lemon</A> When the visitor c****s on any of those words, they are sent to "result.php" On the "result.php" page, is there something that will show what the visitor c****ed on? For example (this doesn't work, but this shows what I'm looking for): Hello visitor, you c****ed on: <?php print $_server{path}; ?> |
|
|
#2 |
|
|
<A HREF="result.php?fruit=apple">apple</A> <A HREF="result.php?fruit=banana">banana</A> <A HREF="result.php?fruit=orange">orange</A> <A HREF="result.php?fruit=grape">grape</A> <A HREF="result.php?fruit=lemon">lemon</A> on results.php have something like if(isset(get['fruit'])) { echo get['fruit']; } else { echo "You did not come from here c****ing a fruit link"; } |
|
|
#3 |
|
|
"Westcoast Sheri" <sheri_deb88@nospamun8nospam.com> wrote in message news:40D5DC84.6BC2494B@nospamun8nospam.com... > How can a PHP result page show what the visitor c****ed on to get to > that page, without using Forms? > > Example: a webpage has the following words: > > <A HREF="result.php">apple</A> > <A HREF="result.php">banana</A> > <A HREF="result.php">orange</A> > <A HREF="result.php">grape</A> > <A HREF="result.php">lemon</A> > > When the visitor c****s on any of those words, they are sent to > "result.php" > > On the "result.php" page, is there something that will show what the > visitor c****ed on? > > For example (this doesn't work, but this shows what I'm looking for): > > Hello visitor, you c****ed on: > <?php > print $_server{path}; > ?> > > Sheri, Two methods come to mind, and both are easy to implement. The simplest method is to set and retrieve the parameter as part of the URL, by appending it to the destination in the following manner: <A HREF="result.php?fruit=banana">banana</A> The receiving script (result.php) then accesses the superglobal array $_GET, with the argument of "fruit" as follows: $choice = $_GET['fruit']; A second method is to put some user interface elements inside a FORM on the web page, and use the POST method to send them to result.php. Then you can retrieve them from the superglobal array $_POST just like in the previous example for GET. Here is a snippet that posts and retrieves the same list as you showed: <!-- This code is part of an HTML or a PHP page -> <!-- HTML Header and body information sent prior to this code... --> <FORM method="post" action="result.php"> <SELECT name="fruit" size="1"><!-- Note: size=1 gives a drop-down list --> <OPTION value="apple" SELECTED>apple</option> <OPTION value="banana">banana</option> <OPTION value="orange">orange</option> <OPTION value="grape">grape</option> <OPTION value="lemon">lemon</option> </SELECT> <INPUT type="submit" value="Submit Choice"> </FORM> <!-- rest of HTML page and footer stuff --> Then in result.php $choice = $_POST['fruit']; echo "\$choice = $choice\n"; |
|
|
#4 |
|
|
> The receiving script (result.php) then accesses the superglobal array $_GET,
> with the argument of "fruit" as follows: > $choice = $_GET['fruit']; > > A second method is to put some user interface elements inside a FORM on the > web page, and use the POST method to send them to result.php. Then you can > retrieve them from the superglobal array $_POST just like in the previous > example for GET. Here is a snippet that posts and retrieves the same list as > you showed: > > <!-- This code is part of an HTML or a PHP page -> > <!-- HTML Header and body information sent prior to this code... --> > <FORM method="post" action="result.php"> > <SELECT name="fruit" size="1"><!-- Note: size=1 gives a drop-down list --> > <OPTION value="apple" SELECTED>apple</option> > <OPTION value="banana">banana</option> > <OPTION value="orange">orange</option> > <OPTION value="grape">grape</option> > <OPTION value="lemon">lemon</option> > </SELECT> > <INPUT type="submit" value="Submit Choice"> > </FORM> > <!-- rest of HTML page and footer stuff --> > > Then in result.php > > $choice = $_POST['fruit']; > echo "\$choice = $choice\n"; Thank you, but no... it won't be practical. I failed to mention that there won't be just 5 choices. There will actually be nearly 1000 (yes, 1000) choices. I know that <A HREF="result.php?fruit=banana">banana</A> will work, but I would have to mention "banana" twice, which will double the size of my html page. I was hoping that there was some PHP variable that could be retrieved. |
|
|
#5 |
|
|
Westcoast Sheri wrote:
>>The receiving script (result.php) then accesses the superglobal array $_GET, >>with the argument of "fruit" as follows: >>$choice = $_GET['fruit']; >> >>A second method is to put some user interface elements inside a FORM on the >>web page, and use the POST method to send them to result.php. Then you can >>retrieve them from the superglobal array $_POST just like in the previous >>example for GET. Here is a snippet that posts and retrieves the same list as >>you showed: >> >><!-- This code is part of an HTML or a PHP page -> >><!-- HTML Header and body information sent prior to this code... --> >><FORM method="post" action="result.php"> >><SELECT name="fruit" size="1"><!-- Note: size=1 gives a drop-down list --> >><OPTION value="apple" SELECTED>apple</option> >><OPTION value="banana">banana</option> >><OPTION value="orange">orange</option> >><OPTION value="grape">grape</option> >><OPTION value="lemon">lemon</option> >></SELECT> >><INPUT type="submit" value="Submit Choice"> >></FORM> >><!-- rest of HTML page and footer stuff --> >> >>Then in result.php >> >>$choice = $_POST['fruit']; >>echo "\$choice = $choice\n"; > > > Thank you, but no... it won't be practical. I failed to mention that there > won't be just 5 choices. There will actually be nearly 1000 (yes, 1000) > choices. > I know that <A HREF="result.php?fruit=banana">banana</A> will work, but I would > have to mention "banana" twice, which will double the size of my html page. > I was hoping that there was some PHP variable that could be retrieved. > How are you going to set the variable?? Either way, you still have 1000 choices and the choices must appear in someway on your web page, unless you use an input text box and check for exact spelling etc... I have had to do this in the past using CGI (PHP wasn't around when I developed it...) and there were 43000+ choices per month. Since the choices could break down into subgroups, I would have them select a subgroup, then give them the choices from the subgroup or a sub-subgroup. Do the "clients" - those who access this site - use dialup or are they "internal"? If internal only then the size of your HTML won't matter that much... if they are mostly dialup, you would need to look at something like subgroups to achieve a "faster" option. Bottom line is that unless you are using text boxes to get the input - and only relying on links or drop-down lists you will have this problem. BTW, I prefer to POST instead of having these URL's that can wrap around the equator... personal preference, YMMV. Michael Austin. |
|
|
#6 |
|
|
Westcoast Sheri schrieb:
>> $choice = $_POST['fruit']; >> echo "\$choice = $choice\n"; > > Thank you, but no... it won't be practical. I failed to mention that there > won't be just 5 choices. There will actually be nearly 1000 (yes, 1000) > choices. > I know that <A HREF="result.php?fruit=banana">banana</A> will work, but I would > have to mention "banana" twice, which will double the size of my html page. > I was hoping that there was some PHP variable that could be retrieved. No, there isn't. The content of the a-Element is not transfered in a HTTP request. If size matters (no, I won't talk about V**gr*) then use some shorter syntax. I ***ume, that the data for the different links is stored in a database or a textfile with a unique id for each entry. Now we use this id for the link. <a href='newpage.php?1>apple</a> <a href='newpage.php?2>banana</a> .... In newpage.php check $_SERVER["REQUEST_URI"] to get the number after the question mark. Now lookup your database for the entry with the appropriate id and your script has the information you wanted it to have. Regards, Matthias |
|
|
#7 |
|
|
Sound like you are looking for a "link tracker". In the meantime, you can try this:
============= for the html page ======== <html> <body> <A HREF="result.php?name=apple">apple</A> <A HREF="result.php?name=banana">banana</A> <A HREF="result.php?name=orange">orange</A> <A HREF="result.php?name=grape">grape</A> <A HREF="result.php?name=lemon">lemon</A> </body></html> ================= for "result.php" ============= <?php if(!empty($_GET['name'])) { $name = $_GET['name']; echo "You c****ed on: ".$name; } ?> I hope this will help you ! Jay |
|
|
#8 |
|
|
On Sun, 20 Jun 2004 21:13:09 GMT, Michael Austin
<maustin@firstdbasource.com> wrote: >> Thank you, but no... it won't be practical. I failed to mention that there >> won't be just 5 choices. There will actually be nearly 1000 (yes, 1000) >> choices. do you expect any user to scan a page of 1000 links? in your case, program a search function where the user can enter the name of the fruit (or part of it) in a search field and do a search in your database. Then only show the results from the search which should not be mor than a few. Regards Marian -- Tipps und Tricks zu PHP, Coaching und Projektbetreuung http://www.heddesheimer.de/coaching/ |
|
|
#9 |
|
|
I noticed that Message-ID: <40D5F5FE.E9ECD076@nospamun8nospam.com> from
Westcoast Sheri contained the following: >I know that <A HREF="result.php?fruit=banana">banana</A> will work, but I would >have to mention "banana" twice, which will double the size of my html page. if you use <A HREF="result.php?banana">banana</A> and all the words are approximately the same length you are talking 6K. Peanuts. But I'd agree 1000 was too many. You need to categorise them. -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies. My opinions, not the committee's, mine. Simple RFDs http://www.ckdog.co.uk/rfdmaker/ |