Jump to content


Photo

Dynamic Script Help!!


  • Please log in to reply
6 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 09 March 2006 - 04:52 PM

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

#2 fusionpixel

fusionpixel
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 09 March 2006 - 05:00 PM

[!--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) View Post[/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"
Did you know there is a manual for PHP? [a href="http://" target="_blank"]http://www.php.net[/a]
Did you know there is a manual for mySQL? [a href="http://" target="_blank"]http://www.mysql.org[/a]

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 March 2006 - 05:05 PM

Part 1:
<a href="sportFind.php?sport=cricket">Cricket</a>
<a href="sportFind.php?sport=tiddleywinks">Tiddleywinks</a>

Part 2:
<?php
// sportFind.php
$sport = $_GET['sport']; // retrieve passed variable
... more code follows ...

Legend has it that reading the manual never killed anyone.
My site

#4 fusionpixel

fusionpixel
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 09 March 2006 - 05:13 PM

[!--quoteo(post=353308:date=Mar 9 2006, 11:05 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Mar 9 2006, 11:05 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Part 1:
<a href="sportFind.php?sport=cricket">Cricket</a>
<a href="sportFind.php?sport=tiddleywinks">Tiddleywinks</a>

Part 2:
<?php
// sportFind.php
$sport = $_GET['sport']; // retrieve passed variable
... more code follows ...
[/quote]

hats off to the admin. :)
Did you know there is a manual for PHP? [a href="http://" target="_blank"]http://www.php.net[/a]
Did you know there is a manual for mySQL? [a href="http://" target="_blank"]http://www.mysql.org[/a]

#5 pearljam73

pearljam73
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 09 March 2006 - 05:56 PM

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>";
}

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 March 2006 - 06:06 PM

[!--quoteo(post=353314:date=Mar 9 2006, 12:56 PM:name=pearljam73)--][div class=\'quotetop\']QUOTE(pearljam73 @ Mar 9 2006, 12:56 PM) View Post[/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 :)
Legend has it that reading the manual never killed anyone.
My site

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 March 2006 - 06:11 PM

[!--quoteo(post=353314:date=Mar 9 2006, 05:56 PM:name=pearljam73)--][div class=\'quotetop\']QUOTE(pearljam73 @ Mar 9 2006, 05:56 PM) View Post[/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.

EDIT: Andy beat me :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users