Pyro4816 Posted January 1, 2011 Share Posted January 1, 2011 For this example, $row2['author'] = "1" $user = 'user'.$row2['author']; if (!isset($$user)){ $result = $connector->query('SELECT * FROM users WHERE ID = '.$row2['author']); $$user = $connector->fetchArray($result); } echo '<a href="user.php?user='.($$user['ID']).'">'.$$user.'</a></p>'; The problem is it is a weird variable that also has an array, but when i use echo $$user['ID']; It errors out saying Notice: Undefined variable: u So I am wondering how to word it to set the variable up properly, and how to call items in the array. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/223105-complicated-stringarrayvariable-issue/ Share on other sites More sharing options...
Pyro4816 Posted January 1, 2011 Author Share Posted January 1, 2011 It wouldn't let me edit again, but an update on it is that echo $user1['ID']; Works, but since this is in a while loop, and i am trying to prevent too many server queries, im trying to set it so that if i need user 1's info again it wont query the database again, but it will query it if there is a user 2 who has not had his info retrieved. Link to comment https://forums.phpfreaks.com/topic/223105-complicated-stringarrayvariable-issue/#findComment-1153456 Share on other sites More sharing options...
joel24 Posted January 1, 2011 Share Posted January 1, 2011 are you intending to use a variable variable...? if (!isset($$user)){ echo $$user['ID']; you're using the $$user variable variable 4 times in that script. unless you have a need for a variable variable, just use $user Link to comment https://forums.phpfreaks.com/topic/223105-complicated-stringarrayvariable-issue/#findComment-1153461 Share on other sites More sharing options...
Pyro4816 Posted January 1, 2011 Author Share Posted January 1, 2011 i am trying to use a variable variable, the problem lies in using the array from a variable variable. Link to comment https://forums.phpfreaks.com/topic/223105-complicated-stringarrayvariable-issue/#findComment-1153481 Share on other sites More sharing options...
joel24 Posted January 1, 2011 Share Posted January 1, 2011 I would use an array from the start i.e. $user = 'user'.$row2['author']; $userArray = array(); if (!isset($$user)){ $result = $connector->query('SELECT * FROM users WHERE ID = '.$row2['author']); $userArray[$user] = $connector->fetchArray($result); } echo '<a href="user.php?user='.$userArray[$user]['ID'].'">'.$user.'</a></p>'; play around with that, otherwise do print_r($$user); to ensure the variable variable array is setup as you wish. Link to comment https://forums.phpfreaks.com/topic/223105-complicated-stringarrayvariable-issue/#findComment-1153487 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.