DarkenedHeart Posted October 7, 2007 Share Posted October 7, 2007 Its not often i need help for anything but i havnt got the time to spend ages to work out what the problem is. Ok from a textarea i have data (A username on each line) which is being posted. and then on the next page it splits the lines up and then trys to get data from them. Here is the code i have: $array = explode("\n", trim($_POST['pm_to'])); foreach ($array as $a) { $result = mysql_query("SELECT u.*, g.* FROM boreded_user u, boreded_gold g WHERE u.user_name='".$a."' AND u.user_id=g.id"); $row = mysql_fetch_assoc($result); $lastlogin = date("d/m/y", $row['user_lastvisit']); $join = date("d/m/y", $row['user_join']); $text .= "<tr><td class='forumheader3'>".$a."</td><td class='forumheader3'>".$row['user_ip']."</td><td class='forumheader3'>".$row['gold']."</td><td class='forumheader3'>".$lastlogin."</td><td class='forumheader3'>".$join."</td></tr>"; } If i have entered say: Name1 Name2 Name3 In the textarea and then clicked on the next page. The script above displays the data OK for Name3, but Name2 and Name1 dont get any data displayed. Does anyone know what i am doing wrong and how i can fix this? Quote Link to comment https://forums.phpfreaks.com/topic/72186-solved-foreach-help/ Share on other sites More sharing options...
haaglin Posted October 7, 2007 Share Posted October 7, 2007 I think trim also removes \n.. try this: $array = explode("\n", $_POST['pm_to']); foreach ($array as $a) { $a = trim($a); $result = mysql_query("SELECT u.*, g.* FROM boreded_user u, boreded_gold g WHERE u.user_name='".$a."' AND u.user_id=g.id"); $row = mysql_fetch_assoc($result); $lastlogin = date("d/m/y", $row['user_lastvisit']); $join = date("d/m/y", $row['user_join']); $text .= "<tr><td class='forumheader3'>".$a."</td><td class='forumheader3'>".$row['user_ip']."</td><td class='forumheader3'>".$row['gold']."</td><td class='forumheader3'>".$lastlogin."</td><td class='forumheader3'>".$join."</td></tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/72186-solved-foreach-help/#findComment-364020 Share on other sites More sharing options...
DarkenedHeart Posted October 7, 2007 Author Share Posted October 7, 2007 Thanks, it works well. I feel ashamed lol that was such a simple answer. Quote Link to comment https://forums.phpfreaks.com/topic/72186-solved-foreach-help/#findComment-364055 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.