/    Sign up×
Community /Pin to ProfileBookmark

Sending info to php page

I have a line in my web page that shows a series of years. When you click on a year it would normal open the page that is predetermined to show only that year. I would like to so that it would bring over that year and sort by that year.

Currently
link on html page
<a href=”Player_Roster2010.php”>2010</a><br />

Currently
<?php
$query = “SELECT * FROM players
WHERE playeryear = 2010
ORDER BY number”;
$players = mysql_query($query);
?>

So in a nut shell when I click on 2010 it would open Player_Roster.php file and sort 2010?

Thanks for all you help.

I have been reading a lot on this site don’t yet get it, but hoping to soon…

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@spufiMar 06.2012 — The year needs to be passed as a variable in the link so it can be grabbed via a get statement.

<i>
</i>$currentYear = date('Y');
$year = array();

for ($i = 1900; $i &lt;= $currentYear; $i++) {
?&gt;
&lt;a href="Player_Roster.php?number=&lt;?php $year($i); ?&gt;"&gt;&lt;?php $year($i); ?&gt;&lt;/a&gt;&lt;br /&gt;
&lt;?php
}


<i>
</i>&lt;?php
$number = $_GET[number];
$query = "
SELECT *
FROM players
WHERE playeryear = $number
ORDER BY $number
";
$players = mysql_query($query);
?&gt;


Not the exact code, but you get the idea. Change the year 1900 to whatever you need.

EDIT: I totally screwed up. Fixing.

P.S. You might want to look into using PDO for your DB stuff.

http://php.net/manual/en/book.pdo.php

http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

Don't want to end up like this.

http://xkcd.com/327/
Copy linkTweet thisAlerts:
@jeffh13_msn_comauthorMar 07.2012 — Ok I understand.
[CODE]<!-- Show Players Information-->
<?php
$inputyr = $_GET[inputyr];
$query = "SELECT * FROM players
WHERE playeryear = $inputyr;
ORDER BY number";
$players = mysql_query($query);
?>[/CODE]


I don't understand.
[CODE]$currentYear = date('Y');
$year = array();

for ($i = 1900; $i <= $currentYear; $i++) {
?>
<a href="Player_Roster.php?inputyr=<?php $year($i); ?>"><?php $year($i); ?></a><br />
<?php
}[/CODE]


This is what I get... Error.jpg.

I'm sorry when i read it this morning I though it made sense... I don't know maybe I'm just being dumb...

Thanks...
Copy linkTweet thisAlerts:
@spufiMar 07.2012 — You need <?php before the $currentYear code.
Copy linkTweet thisAlerts:
@jeffh13_msn_comauthorMar 07.2012 — Ooopppsss....

Well I got farther it opens the correct page but it doesn't show information.

Current code html page.
[CODE]<?php
$currentYear = date('Y');
$year = array();

for ($i = 2011; $i <= $currentYear; $i++) {
?>
<a href="Player_Roster.php?inputyr=<?php $year($i); ?>">2011<?php $year($i); ?></a><br />
<?php
} ?>[/CODE]


Current code for php page.
[CODE]<?php
$inputyr = $_GET[inputyr];
$query = "SELECT * FROM players
WHERE playeryear = $inputyr;
ORDER BY number";
$players = mysql_query($query);
?>[/CODE]


Thanks for your help...

One step at a time...
Copy linkTweet thisAlerts:
@spufiMar 07.2012 — I'm going to bed. I will look at it tomorrow, but it won't be until the afternoon so if anybody wants to chip in, do so.
Copy linkTweet thisAlerts:
@spufiMar 07.2012 — I assume the database stuff didn't work since the link wasn't working in the first place. I have no clue why it seems to force me to use PHP to generate HTML. Here's at least the first statement so you can see if the rest works.

<i>
</i>&lt;?php
$currentYear = date('Y');

for ($i = 2011; $i &lt;= $currentYear; $i++) {
echo "&lt;a href="Player_Roster.php?inputyr=$i"&gt;$i&lt;/a&gt;&lt;br /&gt;";
}
?&gt;
Copy linkTweet thisAlerts:
@jeffh13_msn_comauthorMar 07.2012 — I'm sorry...

This is what i get...

[code=html]http://owblackhawkfootball.com/Black_Hawk_Zone.html[/code]

I don't mean to be a pain I really do appreciate the help. If you want to stop I do understand I'll look at a different way of doing this.

Thanks...
Copy linkTweet thisAlerts:
@spufiMar 08.2012 — You get where? Is that the link that my code generates? You need to send it to a php page since you will need a server side script to process the $_GET data.
Copy linkTweet thisAlerts:
@jeffh13_msn_comauthorMar 09.2012 — Thanks I got it...

[CODE]<?php
$inputyr = $_GET[inputyr];
$query = "SELECT * FROM players
WHERE playeryear = $inputyr;
ORDER BY number";
$players = mysql_query($query);
?>[/CODE]


I never saw it until I did a line by line review...

I have a ; behind Where playeryear = $inputyr....

Dumb... Thanks for your patience....
Copy linkTweet thisAlerts:
@spufiMar 09.2012 — I copied the SQL statement that didn't have the error so that might have been why I didn't pick up on it. I copied in the one that did after you mentioned it and my IDE didn't toss an error. Interesting. Glad you sorted it out though.

P.S. This is why I have started to keep the quotes and semicolon separate from the SQL and I format the code the way I do.
×

Success!

Help @jeffh13_msn_com spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...