![]() |
Question about "isset"
I'm wondering if the following is even possible, and if so, how do I go about fixing what I already have.
So when I go to "stats.php?STAT_ID=X" I want it to grab and run a query based on what X is. PHP Code:
Thanks in advance! |
Wrong:
Code:
. ' ORDER BY \'' . $stat_id . '\' DESC 'Code:
. ' ORDER BY `'' . $stat_id . '` DESC 'I am *assuming* that $stat_id is supposed to be the name of an existing field (a.k.a. "column", though that's a misnomer) in the table. And if that is so, then THIS line is also a mistake: Code:
$stat_id = mysql_real_escape_string($_GET['STAT_ID']);Unless you have field names that include spaces or other non-standard characters, I wouldn't use Code:
stripslashes($_GET['STAT_ID']);Tell you what, give me a list of *ALL* the field names in your batters_career_stats table and we will rewrite this simpler. |
So I've got: PNum, Team_ID, POS_ID, Pos, FName, LName, Team, Year, G, AB, H, R, 2B, 3B, HR, RBI, BB, HP, K, SB, CS
So yeah I'm looking to write a simple code and .php file that will get the the top 50 for the above stat (all those after Year) that I choose, rather than writing a different .php file for each. Along the same lines, not sure if it's possible, but say I needed to use multiple stats in the same query. For instance AVG would be H/AB. I could obviously just simply write another .php file for that specific stat, but if this could somehow be dealt with in one code that would be great. |
So instead of mucking with all this stuff:
Code:
if (get_magic_quotes_gpc()) Code:
<html> |
And I think I have OBP correct. You can easily fix that. And you can see how to derive other stats, as well. No?
Note that AVG needs those back ticks around it `AVG` because AVG is a MySQL keyword. It can't hurt to put them around other fields. |
Hmm, after tying up a few loose ends on the php side, I'm just getting a blank page.
Looking at the html source it's showing a repetition of the following: PHP Code:
|
Whoops...I had " inside of ".
Code:
echo "<tr class=\"$cls\"><td>$rank</td><td>$player</td><td>$pos</td><td>$year</td><td>$stat</td></tr>\n";Hey, I told you I don't code in PHP. <grin/> (But I should have caught that one...so should you.) |
*IF* that doesn't work--but I think it should--you can go back to your printf() solution.
But just use my variable names, including especially $stat, in place of what you were using. |
After more tweaking, I was wondering how to go about making two "isset"s for one page.
So previously we had it by STAT_ID what if I also wanted to grab those STAT values for whichever TEAM_ID I put in? /../stats.php?STAT_ID=AVG&Team_ID=ATL is this something that I need to add to the isset function? |
Do you know what isset means???
Apparently not. Look here: http://php.net/manual/en/function.isset.php isset is NOTHING BUT a simple builtin PHP function that allows you to test to see if there is any value there at all. You don't even NEED to use it for STAT_ID if you use the code I showed you, because that code will only allow certain values for STAT_ID and reject the rest. Now... If you want to make the team abbreviation *optional* then, yes, using isset with it is a good idea. If you want to make it required, you can still use it though you would do so differently. You could alter the code above like this (stuff added is in red, rest stays the same): Code:
<? |
| All times are GMT +1. The time now is 04:48 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.