unistake Posted June 18, 2014 Share Posted June 18, 2014 (edited) Hi guys, Having trouble trying to show values from my $friend array. Only the first friend code is being displayed in my output. There are several fields in my mysql associated with the $sql. Any ideas? Thanks $sql = "SELECT * FROM friends WHERE Code = '$code' OR FriendCode = '$code' AND Status ='A'"; $result = mysqli_query($cxn,$sql) or die ("Can't get friends."); $friend = array(); while($row=mysqli_fetch_array($result)) { if($code == $row['FriendCode']) { $friend[] = $row['Code']; } elseif($code == $row['Code']) { $friend[] = $row['FriendCode']; } foreach($friend as $key => $value) { echo $value.'<br />'; } Edited June 18, 2014 by unistake Quote Link to comment https://forums.phpfreaks.com/topic/289193-foreach-array/ Share on other sites More sharing options...
Solution cyberRobot Posted June 18, 2014 Solution Share Posted June 18, 2014 I would imagine that the query should return results which have "Code" equal to $code and "Status" equal to 'A'...or "FriendCode" equal to $code and "Status" equal to 'A'. If that's the case, you'll want to add parenthesis around Code and FriendCode: $sql = "SELECT * FROM friends WHERE (Code = '$code' OR FriendCode = '$code') AND Status ='A'"; Quote Link to comment https://forums.phpfreaks.com/topic/289193-foreach-array/#findComment-1482829 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.