Jump to content

[SOLVED] foreach help


DarkenedHeart

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/72186-solved-foreach-help/
Share on other sites

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>";
}

Link to comment
https://forums.phpfreaks.com/topic/72186-solved-foreach-help/#findComment-364020
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.