peeaitchpee Posted July 17, 2009 Share Posted July 17, 2009 I'm having an issue grabbing the value of a variable, it's asyntax issue and i'm drawing a blank $which = "nav_order"; // nav_order is the column name in a mysql db $sql = "SELECT `id`, `$which` FROM `nav` WHERE `$which` <= '$order' ORDER BY `$which` DESC LIMIT 0, 2"; $result = mysql_query($sql, $connection) or die ("Couldn't execute query."); $row = mysql_fetch_array($result); // this works fine $this_order = $row['$which']; This is the issue. I cannot get the value of the 'nav_order' column. I thought it was $this_order = $row['{$}which'];, but this is not working, nor is $this_order = $row['$$which']; Thanks in advance Link to comment https://forums.phpfreaks.com/topic/166367-solved-variable-variables/ Share on other sites More sharing options...
Alex Posted July 17, 2009 Share Posted July 17, 2009 $this_order = $row[$which]; Anything inside of single quotes will be evaluated as a string. So technically what you had was saying $row['$which'] Actually the string '$which' and not the value of $which. Link to comment https://forums.phpfreaks.com/topic/166367-solved-variable-variables/#findComment-877297 Share on other sites More sharing options...
peeaitchpee Posted July 17, 2009 Author Share Posted July 17, 2009 wow. only took a few seconds to embarass me. That's the one thing I didnt bother trying. Thanks! Link to comment https://forums.phpfreaks.com/topic/166367-solved-variable-variables/#findComment-877304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.