Jim R Posted January 11, 2015 Share Posted January 11, 2015 I'm creating this URL to pass variables to use from one Page to another: http://eg10basketball.com/playerinfo/?nameFull=Evan-Borgman&team=16 My WP site is seeing the first variable but not the second. After some searching I've found this suggestion, but it's not working for me: function add_query_vars_filter( $vars ) { $vars[] = "nameFull"; $vars[] = "team"; return $vars; } add_filter( 'query_vars', 'add_query_vars_filter' ); I tried putting this in the wp-includes/functions.php file of the, but ended up with a fatal error. I have since added it to my theme's functions.php file. There isn't an error, but it doesn't yield recognition of my second variable. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted January 11, 2015 Share Posted January 11, 2015 This explains the entire process well. http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/ Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 Whenever I put that in functions.php, I get an error. Is it because I haven't done the second part? Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) I can't get any of it in there without getting the error. Which functions page? The one in my theme or the one in wp-includes? Edited January 12, 2015 by Jim R Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 I have two areas drawing information my database based on the variables passed from a Roster Page to a Profile Page. On the Profile Page, there are two queries, one in main/body and one in the sidebar. The main/body area is working. The sidebar isn't. Below the: echo $team produces nothing. Here is the page in question: http://eg10basketball.com/playerinfo/?nameFull=Evan-Borgman&team=16 Here is the error I'm getting: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home4/jwrbloom/public_html/eg10basketball.com/resources/roster-widget.php on line 14 $team = $_GET['team']; echo $team; $query = 'SELECT * FROM a_players WHERE team= '. $team .' ORDER BY nameLast ASC'; $results = mysql_query($query); $count = 0; while($line = mysql_fetch_assoc($results)) { $count = $count+1; echo '<div><a href="http://eg10basketball.com/playerinfo?nameFull=' . $line['nameFirst'] . '-' . $line['nameLast'] . '">'. $line['nameFirst'] . ' ' . $line['nameLast'] .'</a><br></div>'; } Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 It's not getting the value for 'team'. Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 Would it make any difference that the second variable is a number? I tested it by removing the first variable, 'nameFull', and 'team' alone doesn't produce any results. So under no circumstance does it pass the team number to the second page, even though it clearly passes the team number 16 to the second page's URL. Quote Link to comment Share on other sites More sharing options...
wezhind Posted January 12, 2015 Share Posted January 12, 2015 (edited) So what happens when you echo $_GET['nameFull']; and echo $_GET['team']; What info does it show? Also what does the $query look like? Perhaps echo $query also to see what SQL is being created? Are you certain team isn't being passed and the query has another type of error? edit: sorry just noticed you echoing $team already. but would be interested to see what is in nameFull when echoed. Edited January 12, 2015 by wezhind Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 12, 2015 Share Posted January 12, 2015 You can always try printing out the global variable $_GET try this echo '<pre>'; print_r($_GET); echo '</pre>'; it will show all the variables sent through Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted January 12, 2015 Share Posted January 12, 2015 $team = $_GET['team'];echo $team; $query = 'SELECT * FROM a_players WHERE team= '. $team .' ORDER BY nameLast ASC';$results = mysql_query($query);$count = 0;while($line = mysql_fetch_assoc($results)) {I cleaned up your code a little bit. <?php $team = mysql_escape_string($_GET['team']); if(is_int($team)){ $query = "select `nameFirst`, `nameLast` from `a_players` where 'team' = '{$team}' order by nameLast asc"; $results = mysql_query($query); $count = 0; //why are you counting if you mind me asking while($player = mysql_fetch_assoc($results)) { $nameFirst = $player['nameFirst']; $nameLast = $player['nameLast']; echo <<<EOT <div> <a href="http://eg10basketball.com/playerinfo?nameFull={$nameFirst}-{$nameLast}">{$nameFirst} {$nameLast}</a> <br> </div> EOT; } } Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 When I echo $playerName it show (in the case of this page) Evan-Borgman. I have flipped flopped the GET's. $_GET('nameFull') always works, $_GET('team') never works. I keep looking to make sure it isn't some syntax error. @chriscloyd, I'll have to try that out after a meeting. I wanted to answer the question of what shows up when I echo nameFull. I'll have to keep the SELECT * though because I'll be adding more information to the printout. That was just a quick port from another instance where it was just a list of names. Does it matter that I have two GETs on the page? My instinct says no, and I did flip flop the GET's (instances) on my page with the same result. Here is the side that is working: $playerName = $_GET['nameFull']; //echo $playerName; $query = 'SELECT * FROM a_players ORDER BY uniform ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { $nFirst = $line['nameFirst']; $nLast = $line['nameLast']; $nameFull = "{$nLast}{$nFirst}"; if ($playerName == $line['nameFirst'].'-'.$line['nameLast']) { echo ' <div class="profile">'; echo '<div class="profileName">' .$line['nameFirst'] . ' ' .$line['nameLast'] . '</div>'; echo '<div>'. $line['feet'] . '\'' . $line['inches'] . '", '; if ($line['position'] == 'PG') {echo 'Point Guard';} elseif ($line['position'] == 'SG') {echo 'Shooting Guard';} elseif ($line['position'] == 'SF') {echo 'Small Forward';} elseif ($line['position'] == 'PF') {echo 'Power Forward';} elseif ($line['position'] == 'C') {echo 'Center';} echo '</div>'; //echo '<img src="http://spieceindyheat.com/2015/images/player_boards/hardwoodBW/' . strtolower($nLast) .'' . $line['nameFirst'] . '.png" width="250">'; echo '<div>Class of 20' . $line['team']. '</div>'; echo '<div>'; if (!isset($line['city'])) { echo $line['school'] .' HS'; } else { echo $line['city'] . ' ('. $line['school'] . ')'; } echo '</div><!--more-->'; if ($line['team'] < 19) { echo '<div>Coach ' . $line['coachSchool'].'</div>'; } // echo $line['schoolAddress'] . '<br>'; // echo $line['schoolCity'] . ' IN, ' . $line['schoolZip'] . '<br>'; // echo $line['schoolPhone']; echo '</div> <hr class="profile">'; } } Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 I made the change. It's not echo $team, so it's not GETting anything. That's the perplexing part. No matter how I use team=16, it doesn't pass the value. I have even tried it as the only value. Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 (Thank you for unlocking the topic.) I tried the global GET: it produced Array ( [nameFull] => Evan-Borgman ) Interestingly, I read something somewhere that said to add %26 (numerical ampersand value), and this is what I got: Array ( [nameFull] => Evan-Borgman [&team] => 16 ) So I changed the top of the code to: $team = $_GET['&team']; echo $team; And it produced the correct 16. However, it's still not taking $team = 16 and using it in the query. Quote Link to comment Share on other sites More sharing options...
Jim R Posted January 12, 2015 Author Share Posted January 12, 2015 I went back to this query: SELECT * FROM a_players WHERE team=' .$team.' ORDER BY nameLast ASC'; Everything appears to be working. Does anyone have any idea why adding %26 would change the results of what even gets noticed? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted January 12, 2015 Share Posted January 12, 2015 Always start off looking at the total $_GET variable and not the individual elements. Use one of the following: var_dump($_GET); print_r($_GET); echo('<pre>'.print_r($_GET,1).'</pre>'); //Better for humans to read Evidently, your URL is not well formed. Look into urlencode(). 1 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 12, 2015 Share Posted January 12, 2015 Always start off looking at the total $_GET variable and not the individual elements. Use one of the following: var_dump($_GET); print_r($_GET); echo('<pre>'.print_r($_GET,1).'</pre>'); //Better for humans to read Evidently, your URL is not well formed. Look into urlencode(). He is using wordpress, which restricts/filters $_GET, which is why this seeminhly easy problem is a bit more complex since it appears the global $_GET is being manipulated. 1 Quote Link to comment Share on other sites More sharing options...
Masonh928 Posted January 18, 2015 Share Posted January 18, 2015 1 thing to add (not sure if already said) but you should be using MySqli or PDO for DBase interaction. You could try… Die($_GET); It will kill the script and just print out the variable. (Btw, I live in Indiana too haha.) Quote Link to comment Share on other sites More sharing options...
wezhind Posted February 2, 2015 Share Posted February 2, 2015 Hi. Been away for a while. Not sure of the status of this issue. However, if as CroNiX mentioned a couple of posts back, the $_GET variable is being manipulated, you could 'cheat' and send your info serialised in some manner. Rough example: I don't know the maximum value that your team variable will reach, but say it's under a thousand then you could format the team to be a 4 digit string and add that to your nameFull info i.e. '0016EvanBorger' and then use substr() to split the string into the 2 values you require. I know hardly anything about the workings of WordPress, but is it possible that it only allows one 'value' in the $_GET variable. Does it use a serialise type method to pass variables using the $_GET itself? I don't know... it just popped into my head as a possibility. Quote Link to comment Share on other sites More sharing options...
scootstah Posted February 3, 2015 Share Posted February 3, 2015 If you're still stuck, take a look at this answer: http://stackoverflow.com/a/20228400 Seems to be what you want. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.