Jump to content

Dynamic Script Help!!


essjay_d12

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
Link to comment
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"
Link to comment
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]
Link to comment
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. :)
Link to comment
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>";
}
Link to comment
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 :)
Link to comment
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 :(
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.