Jump to content

Archived

This topic is now archived and is closed to further replies.

essjay_d12

Dynamic Script Help!!

Recommended Posts

I have the following

Football
Rugby
Cricket

I 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+ !!!

Thanks

D

Share this post


Link to post
Share on other sites
[!--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 following

Football
Rugby
Cricket

I 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+ !!!

Thanks

D
[/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"

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[!--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. :)

Share this post


Link to post
Share on other sites
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>";
}

Share this post


Link to post
Share on other sites
[!--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 :)

Share this post


Link to post
Share on other sites
[!--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 :(

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.