Graphi Posted June 22, 2007 Share Posted June 22, 2007 Hi everyone new member here and new to php - only just managed "hello world" Yes I am serious I don't know if its possible using php to solve this, but with all the power it appears to have - it should be? I would appreciate your help with the following situation please: I have a single html page with many named anchors please take a look http://www.conservatoryandporch.com/lincolnshire-towns-and-villages.html Sample code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <h3><A NAME="index"></A> Select a letter below to go directly to Towns and Villages starting with that letter in Lincolnshire </h3> <H3> <A HREF="#A">A</A> <A HREF="#B">B</A> <A HREF="#C">C</A> <A HREF="#D">D</A> <A HREF="#E">E</A> <A HREF="#F">F</A> <A HREF="#G">G</A> <A HREF="#H">H</A> <A HREF="#I">I</A> <A HREF="#K">K</A> <A HREF="#L">L</A> <A HREF="#M">M</A> <A HREF="#N">N</A> <A HREF="#O">O</A> <A HREF="#P">P</A> <A HREF="#Q">Q</A> <A HREF="#R">R</A> <A HREF="#S">S</A> <A HREF="#T">T</A> <A HREF="#U">U</A> <A HREF="#W">W</A> <A HREF="#Y">Y</A> </H3> <A NAME="A"></A> <H5><A HREF="#index">Go back to the Alphabetical Index</A></H5> <H1>A</H1> <TR> <TD VALIGN="TOP" WIDTH="50%"> <UL> <LI><A HREF="Aby/">Aby</A> <LI><A HREF="Addlethorpe/">Addlethorpe</A> <LI><A HREF="Aisthorpe/">Aisthorpe</A> <LI><A HREF="Alford/">Alford</A> <LI><A HREF="Algarkirk/">Algarkirk</A> <LI><A HREF="Alkborough/">Alkborough</A> <LI><A HREF="Althorpe/">Althorpe</A> <LI><A HREF="Alvingham/">Alvingham</A> <LI><A HREF="AmberHill/">Amber Hill</A> <LI><A HREF="Amcotts/">Amcotts</A> <LI><A HREF="Ancaster/">Ancaster</A> <LI><A HREF="Anderby/">Anderby</A> <LI><A HREF="Anwick/">Anwick</A> <LI><A HREF="Apley/">Apley</A> <LI><A HREF="Appleby/">Appleby</A> </UL> </TD> <TD VALIGN="TOP"> <UL> <LI><A HREF="Asgarby/">Asgarby by Sleaford</A> <LI><A HREF="AsgarbySpilsby/">Asgarby by Spilsby</A> <LI><A HREF="Ashby/">Ashby</A> <LI><A HREF="AshbybyPartney/">Ashby by Partney</A> <LI><A HREF="AshbycumFenby/">Ashby cum Fenby</A> <LI><A HREF="AshbydelaLaunde/">Ashby de la Launde</A> <LI><A HREF="AshbyPuerorum/">Ashby Puerorum</A> <LI><A HREF="Aslackby/">Aslackby</A> <LI><A HREF="Asterby/">Asterby</A> <LI><A HREF="Aswarby/">Aswarby</A> <LI><A HREF="Aswardby/">Aswardby</A> <LI><A HREF="Aubourn/">Aubourn</A> <LI><A HREF="Aunsby/">Aunsby</A> <LI><A HREF="Authorpe/">Authorpe</A> <LI><A HREF="Aylesby/">Aylesby</A> </UL></body></html> As you can see at the top is the alphabetical index (A-Y) with named anchors which takes you (jumps) to the appropriate alphabetical group list within the same page. Then clicking on individual Towns at the moment just goes to 404 (no such file exists - yet) Thats just fine, but what I would like to achieve is that when a user clicks on the specific Town, a page is generated in the browser that states something on the lines: "Thank you for your interest. The answer is YES! we do sell what your looking for in "XXX" . Where "XXX" is the name of the Town the user just clicked. The common anchor point to handle is: <A HREF="XXX/"> Can php substitute "XXX" for what ever the user clicked (ignoring the string "#") and provide the appropriate output in the browser? If this is possible, it sure would save me from manually creating all the individual pages for each entry! also it would mean I can just update (maintain) the one resulting page. Hope you understand what Im trying to do? Thanks for any advice. My server variables: http://www.conservatoryandporch.com/test.php Quote Link to comment Share on other sites More sharing options...
Caesar Posted June 23, 2007 Share Posted June 23, 2007 Short answer, yes, that should be simple. You may want to look into two things: 1. Using PHP with MySQL 2. Using $_GET Quote Link to comment Share on other sites More sharing options...
Graphi Posted June 23, 2007 Author Share Posted June 23, 2007 Thanks caesar for your quick response! Not sure what you mean but willing to learn. 1. Yes I have MySQL database 2. Is register_globals a prerequisite for using $_GET because its set to "OFF"? Could you please provide an example header (or code) using $_GET (I will have to put this together piece by piece) Thanks. Quote Link to comment Share on other sites More sharing options...
Caesar Posted June 24, 2007 Share Posted June 24, 2007 If your URL looks like http://mysite.com/index.php?pid=10 Then... <?php $pageid = $_GET['pid']; echo'You are viewing content for Page ID: '.$pageid.''; //Will output..."You are viewing content for Page ID: 10" ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 24, 2007 Share Posted June 24, 2007 2. Is register_globals a prerequisite for using $_GET because its set to "OFF"? Nice to see someone bother to try and find out about stuff and then ask, rather than just asking. To answer the question, no. However, ill give you some detail on register_globals. Fistly, having reister_globals off is a good thing. Having it on is a security issue. What is it though? Well, when it is on, all variables in the POST, GET, SESSION etc arrays are made into variables for the php page. So, refering back to the example posted by Caesar, if your link where: http://mysite.com/index.php?pid=10 Then in index.php, a variable called $pid would already be created with the value 10, WITHOUT this line: <?php $pageid = $_GET['pid']; That line effectively does what register_globals does automatically, but only for the variable $pageid. Hope that makes some sense. Quote Link to comment Share on other sites More sharing options...
Graphi Posted June 29, 2007 Author Share Posted June 29, 2007 Hey many thanks guys! It only took me about an hour to solve this after studying your replies - thats pretty quick for such an slow learner How? 1. I created a PHP file as suggested: test_pageid.php <?php $pageid = $_GET['pid']; echo'Yes we manufacture and install Conservatories and Porches in: '.$pageid.''; ?> 2. Uploaded file via ftp to my test folder 3. Next I modified each of my HTML page links like so: (this is what took so long to figure out) <LI><A HREF="/LEARN-PHP/test_pageid.php?pid=Aby">Aby</A> <LI><A HREF="/LEARN-PHP/test_pageid.php?pid=Addlethorpe">Addlethorpe</A> <LI><A HREF="/LEARN-PHP/test_pageid.php?pid=Aisthorpe">Aisthorpe</A> etc, etc, The response I get is: "Yes we manufacture and install Conservatories and Porches in:" The $pageid depends on what the visitor clicks! Wow! my first PHP script!!! Thanks guys for helping me out. It was important to learn not only how to do this, but also to understand the processes involved of how PHP works and what it can do. Some years ago I remember writing some CGI scripts in Perl and remember well the problems I encountered. I must admit - I thought that having no experience at all with PHP, I was preparing myself to spend many days and nights to get this one (my first) sorted. Again caesar/GingerRobot - thanks for your help, samples and explanations! Quote Link to comment Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 Perl and PHP are similar in a few ways... The functions are sometimes named differently, but as for the logic, it's basically the same ;p. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.