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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.