unistake Posted June 18, 2014 Share Posted June 18, 2014 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 />'; } Link to comment https://forums.phpfreaks.com/topic/289193-foreach-array/ Share on other sites More sharing options...
cyberRobot Posted June 18, 2014 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'"; Link to comment https://forums.phpfreaks.com/topic/289193-foreach-array/#findComment-1482829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.