HCProfessionals Posted March 18, 2011 Share Posted March 18, 2011 I am having trouble with the grid highlighting all users with grid coordinates, though it highlights the currently selected grid coordinate with no problem. $user_map_result = $db->query( "SELECT * FROM map WHERE userID=".$user['uID']."" ); $user_map = $db->fetch( $user_map_result ); $users_map_result = $db->query( "SELECT * FROM map" ); $users_map = $db->fetch( $users_map_result ); function DisplayGrid($gridx,$gridy) { global $x, $y; $bgcolor = null; //highlight all users with grid coordinates if ($gridx == $users_map['x'] && $gridy == $users_map['y']) { $bgcolor = 'bgcolor="#c00000"'; } //highlight currently selected grid coordinate if ($gridx == $x && $gridy == $y) { $bgcolor = 'bgcolor="#c00000"'; } echo "<td width=\"50\" height=\"50\" $bgcolor align=center valign=center><a href=\"map.php?xcord=$gridx&ycord=$gridy\">[X]</a><br><font size=1>($gridx,$gridy)</font></td>"; } Quote Link to comment https://forums.phpfreaks.com/topic/230974-highlighting-table-tds/ Share on other sites More sharing options...
.josh Posted March 18, 2011 Share Posted March 18, 2011 $users_map is not within scope of your function. Either declare it as a global variable or pass it to the function. Quote Link to comment https://forums.phpfreaks.com/topic/230974-highlighting-table-tds/#findComment-1188977 Share on other sites More sharing options...
HCProfessionals Posted March 19, 2011 Author Share Posted March 19, 2011 Can you show me an example please? Quote Link to comment https://forums.phpfreaks.com/topic/230974-highlighting-table-tds/#findComment-1189541 Share on other sites More sharing options...
KevinM1 Posted March 19, 2011 Share Posted March 19, 2011 Why are you using global at all? Pass everything through your function's argument list: function DisplayGrid($gridx, $gridy, $x, $y, $users_map) { // do stuff } For more on why global is bad, read through the following thread: http://www.phpfreaks.com/forums/index.php?topic=327433.0 Quote Link to comment https://forums.phpfreaks.com/topic/230974-highlighting-table-tds/#findComment-1189550 Share on other sites More sharing options...
.josh Posted March 19, 2011 Share Posted March 19, 2011 Can you show me an example please? well your current function has some variables being declared as global. It also has variables being passed to it. Do you not know what your own function is doing? Quote Link to comment https://forums.phpfreaks.com/topic/230974-highlighting-table-tds/#findComment-1189592 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.