This is a discussion on newbie...passing hyperlink search string within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, Newbie alert....aaaaaaarrrrrrrrrrgggggggghhhhhhhhh etc. Ok then. Imagine I have a web page with 4 links - cars, trucks, bikes, tractors. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
Newbie alert....aaaaaaarrrrrrrrrrgggggggghhhhhhhhh etc. Ok then. Imagine I have a web page with 4 links - cars, trucks, bikes, tractors. When a user clicks on any of these links it will show a webpage that will go to a mysql database and list each vehicle. For example if they click on trucks it will show a webpage containing all trucks etc. What would be the best way to code this? My first idea would be to have the 4 links linking to 4 separate php pages trucks.php, bikes.php etc etc that would produce each page. But it seems silly to have 4 separate pages when 1 would do as the search is more or less the same except for the query as the query is really saying 'list all the vehicle types that are the type of the hyperlink clicked' If I had just one php page to show the results then how would I pass the vehicle type in the hyperlink to the query? Thanks, TD. ------------------------------------ FREE - Stop Spam Now - FREE http://entier.ecosm.com/link/?obteip |
|
|||
|
If you put this in a link,
<a href="resultpage.php?item=car"> Cars </a> <a href="resultpage.php?item=truck"> Trucks </a> <a href="resultpage.php?item=bike"> Bikes </a> <a href="resultpage.php?item=tractor"> Tractors </a> then the second page can lookup all the item that are a "car" or a "truck" Item is a variable $item in the 2nd page. Goodluck Molle "toedipper" <send_rubbish_here734@hotmail.com> schreef in bericht news:2iv1b1Fr56bmU1@uni-berlin.de... > Hello, > > Newbie alert....aaaaaaarrrrrrrrrrgggggggghhhhhhhhh etc. > > Ok then. > > Imagine I have a web page with 4 links - cars, trucks, bikes, tractors. > When a user clicks on any of these links it will show a webpage that will go > to a mysql database and list each vehicle. For example if they click on > trucks it will show a webpage containing all trucks etc. > > What would be the best way to code this? My first idea would be to have the > 4 links linking to 4 separate php pages trucks.php, bikes.php etc etc that > would produce each page. But it seems silly to have 4 separate pages when 1 > would do as the search is more or less the same except for the query as the > query is really saying 'list all the vehicle types that are the type of the > hyperlink clicked' > > If I had just one php page to show the results then how would I pass the > vehicle type in the hyperlink to the query? > > Thanks, > > TD. > > ------------------------------------ > FREE - Stop Spam Now - FREE > http://entier.ecosm.com/link/?obteip > > > > > |
|
|||
|
It depends on your table design, of course, but here is how I would do it:
Table: vehicles Columns: name, type, etc. Type would be "bike","truck", or something like that. Then you make a PHP page something like this: list_vehicles.php <html><body> <?php //Connection & database selection code here if(!$type || $type == "all") { query = "SELECT * FROM vehicles"; } else { query = "SELECT * FROM vehicles WHERE type = " . $type; } //Retrieve data, generate HTML, and close connection ?> </body></html> Manitoba98XP "toedipper" <send_rubbish_here734@hotmail.com> wrote in message news:2iv1b1Fr56bmU1@uni-berlin.de... > Hello, > > Newbie alert....aaaaaaarrrrrrrrrrgggggggghhhhhhhhh etc. > > Ok then. > > Imagine I have a web page with 4 links - cars, trucks, bikes, tractors. > When a user clicks on any of these links it will show a webpage that will go > to a mysql database and list each vehicle. For example if they click on > trucks it will show a webpage containing all trucks etc. > > What would be the best way to code this? My first idea would be to have the > 4 links linking to 4 separate php pages trucks.php, bikes.php etc etc that > would produce each page. But it seems silly to have 4 separate pages when 1 > would do as the search is more or less the same except for the query as the > query is really saying 'list all the vehicle types that are the type of the > hyperlink clicked' > > If I had just one php page to show the results then how would I pass the > vehicle type in the hyperlink to the query? > > Thanks, > > TD. > > ------------------------------------ > FREE - Stop Spam Now - FREE > http://entier.ecosm.com/link/?obteip > > > > > |
|
|||
|
Personally, I like to do something like the following;
<? if (isset($_GET['type']) { ... // Initialise stuff, set up your environment. switch ($_GET['type']) { case "bikes": ... // Do stuff unique to the bikes page. break; case "trucks": ... // Stuff unique for trucks... break; case "All": ... // Stuff for all types. break; default: ... // Handle any unknown type that might // crop up. } ... // database query stuff and return results. } else { ... // Default stuff in case $_GET['type'] isn't passed. } ?> Whenever you pass query strings to your script you have to always check to see if it exists before you try to do anything with it, otherwise you might get unsightly errors and weird things happening. It's also a good idea to check your data before you do something with it. Beyond malicious DoS attacks, there is simple user error, all of which can mess up how you want your script to work. Never under-estimate your users. ;) On Sat, 12 Jun 2004 01:33:37 +0100, "toedipper" <send_rubbish_here734@hotmail.com> wrote: >Hello, > >Newbie alert....aaaaaaarrrrrrrrrrgggggggghhhhhhhhh etc. > >Ok then. > >Imagine I have a web page with 4 links - cars, trucks, bikes, tractors. >When a user clicks on any of these links it will show a webpage that will go >to a mysql database and list each vehicle. For example if they click on >trucks it will show a webpage containing all trucks etc. > >What would be the best way to code this? My first idea would be to have the >4 links linking to 4 separate php pages trucks.php, bikes.php etc etc that >would produce each page. But it seems silly to have 4 separate pages when 1 >would do as the search is more or less the same except for the query as the >query is really saying 'list all the vehicle types that are the type of the >hyperlink clicked' > >If I had just one php page to show the results then how would I pass the >vehicle type in the hyperlink to the query? > >Thanks, > >TD. > >------------------------------------ >FREE - Stop Spam Now - FREE >http://entier.ecosm.com/link/?obteip > > > > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|