Jump to content

How to display an array?


spires

Recommended Posts

Hi Guys

 

can someone help with out putting an array.

 

I have two textarea fields, 'Keywords' & 'code'.

Both fields can have multiple line of text.

 

I the need the contents of both fields to be outputted

in one text area.

 

 

Example:

keyword - apples

              pear

Code - 1

          2

 

I need it to output:

apples 1

pear 1

 

BUT, it's outputting:

apples 1

apples 2

pear 1

pear 2

 

 

Here is the URL: http://freeadwordsebook.com/test.php

 

Here is my code

<form name="from11" method="post" action"tracker.php">
<input name="type" type="hidden" value="upload">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="300">Keywords:<br>
<textarea name="keywords" cols="25" rows="8" class="body_text" id="keywords"><?PHP echo stripslashes($_POST['keywords']); ?></textarea>
</td>
<td width="300">Code:<br>
<textarea name="code" cols="25" rows="8" class="body_text" id="code"><?PHP echo stripslashes($_POST['code']); ?></textarea>
</td>
</tr>

<tr>
<td>
<input name="submit11" value="submit" type="submit">
</td>

</tr>
</table>
</form>

<br><br>
<textarea name="results" cols="50" rows="8">
<?PHP

if (isset($_POST['submit11'])){

		$keywords = stripslashes($_POST['keywords']);
		$key_array = explode("\n", $keywords);

		$code = stripslashes($_POST['code']);
		$code_array = explode("\n", $code);




// ---------------------------------------------


	foreach ($key_array as $keyword) {
		foreach ($code_array as $cd) {

		$keyword = trim($keyword);
		$cd = trim($cd);


		echo $keyword.$cd."\r\n";
         

		}
		}

}

?>
</textarea>

 

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/102300-how-to-display-an-array/
Share on other sites

 

Hi rajivgonsalves

 

I see what you trying to do, and that is exactly on the right lines.

But now i'm just getting 'A A' as the output results.

 

As you can see here: http://freeadwordsebook.com/test.php

 

New Code

<form name="from11" method="post" action"tracker.php">
<input name="type" type="hidden" value="upload">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="300">Keywords:<br>
<textarea name="keywords" cols="25" rows="8" class="body_text" id="keywords"><?PHP echo stripslashes($_POST['keywords']); ?></textarea>
</td>
<td width="300">Code:<br>
<textarea name="code" cols="25" rows="8" class="body_text" id="code"><?PHP echo stripslashes($_POST['code']); ?></textarea>
</td>
</tr>

<tr>
<td>
<input name="submit11" value="submit" type="submit">
</td>

</tr>
</table>
</form>

<br><br>
<textarea name="results" cols="50" rows="8">
<?PHP

if (isset($_POST['submit11'])){

		$keywords = stripslashes($_POST['keywords']);
		$key_array = explode("\n", $keywords);

		$code = stripslashes($_POST['code']);
		$code_array = explode("\n", $code);




// ---------------------------------------------


for ($i=0;$i<count($code_array);$i++){

		$key_array = trim($key_array);
		$code_array = trim($code_array);


    echo $key_array[$i]." ".$code_array[$i];
}

}

?>
</textarea>

OK,

 

First, thanks for all your help.

I have now got rid of the A A, but now there is one last problem.

 

 

The text is outputting like this:

apples

1

plum

2

banana 3

 

It shouls be like this:

apples 1

plum 2

banana 3

 

 

Any more help please.  :-)

 

<?PHP

if (isset($_POST['submit11'])){

		$keywords = stripslashes($_POST['keywords']);
		$key_array = explode("\n", $keywords);

		$code = stripslashes($_POST['code']);
		$code_array = explode("\n", $code);


// ---------------------------------------------


for ($i=0;$i<count($code_array);$i++){

    echo $key_array[$i]." ".$code_array[$i];
}

}

?>

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.