essjay_d12 Posted March 9, 2006 Share Posted March 9, 2006 I have the followingFootballRugbyCricketI want it that which ever of those 3 the user clicks it runs a script called sportFind.php which would place the 'clicked' word into a variable or directly into the SQL query and then search the database for that sport.I felt this would be better than creating a script for each sport - imagine if you had 20+ !!!ThanksD Quote Link to comment Share on other sites More sharing options...
fusionpixel Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353301:date=Mar 9 2006, 10:52 AM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 9 2006, 10:52 AM) [snapback]353301[/snapback][/div][div class=\'quotemain\'][!--quotec--]I have the followingFootballRugbyCricketI want it that which ever of those 3 the user clicks it runs a script called sportFind.php which would place the 'clicked' word into a variable or directly into the SQL query and then search the database for that sport.I felt this would be better than creating a script for each sport - imagine if you had 20+ !!!ThanksD[/quote]LOL! This is turning into "Request" forum rather than Help forum :).Show us something that you have done to address the issue, i give you a hint "Functions" Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 9, 2006 Share Posted March 9, 2006 Part 1:[code]<a href="sportFind.php?sport=cricket">Cricket</a><a href="sportFind.php?sport=tiddleywinks">Tiddleywinks</a>[/code]Part 2:[code]<?php// sportFind.php$sport = $_GET['sport']; // retrieve passed variable... more code follows ...[/code] Quote Link to comment Share on other sites More sharing options...
fusionpixel Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353308:date=Mar 9 2006, 11:05 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Mar 9 2006, 11:05 AM) [snapback]353308[/snapback][/div][div class=\'quotemain\'][!--quotec--]Part 1:[code]<a href="sportFind.php?sport=cricket">Cricket</a><a href="sportFind.php?sport=tiddleywinks">Tiddleywinks</a>[/code]Part 2:[code]<?php// sportFind.php$sport = $_GET['sport']; // retrieve passed variable... more code follows ...[/code][/quote]hats off to the admin. :) Quote Link to comment Share on other sites More sharing options...
pearljam73 Posted March 9, 2006 Share Posted March 9, 2006 You're not passing the variable through a form, and it's therefore not a GET[] value. Because you're passing it in the address bar, $sport automatically equals the value on the next page.Just start using the $sport variable, like this...$result = mysql_query("SELECT * FROM table_name WHERE Sport='$sport' ORDER BY Sport_Name asc",$db_conn_id);while ($myrow = mysql_fetch_array($result) {echo $myrow['Sport_Name']."<BR>";} Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353314:date=Mar 9 2006, 12:56 PM:name=pearljam73)--][div class=\'quotetop\']QUOTE(pearljam73 @ Mar 9 2006, 12:56 PM) [snapback]353314[/snapback][/div][div class=\'quotemain\'][!--quotec--]You're not passing the variable through a form, and it's therefore not a GET[] value. Because you're passing it in the address bar, $sport automatically equals the value on the next page.[/quote]Au contraire, my friend. Anything passed by URL is retrievable using the GET method. And since current releases of php for quite some time have register_globals set to OFF (as being less insecure), it is necessary to retrieve passed data from the GET array. That'll work whether register_globals is on or off. If you just assume $sport will exist on the next page, you're in for a big surprise when register_globals is off :) Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353314:date=Mar 9 2006, 05:56 PM:name=pearljam73)--][div class=\'quotetop\']QUOTE(pearljam73 @ Mar 9 2006, 05:56 PM) [snapback]353314[/snapback][/div][div class=\'quotemain\'][!--quotec--]You're not passing the variable through a form, and it's therefore not a GET[] value. Because you're passing it in the address bar, $sport automatically equals the value on the next page.Just start using the $sport variable, like this...$result = mysql_query("SELECT * FROM table_name WHERE Sport='$sport' ORDER BY Sport_Name asc",$db_conn_id);while ($myrow = mysql_fetch_array($result) {echo $myrow['Sport_Name']."<BR>";}[/quote]WHAT! You use $_GET[] to get the value(s) from the url! It doesnt matter whether its been submitted by a form or not! PHP will not create $sport automatically unless register_globals is turned On which I highly recommend to be turned Off! AndyB's code is correct.[b]EDIT:[/b] Andy beat me :( 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.