Jump to content

get content of array


clankill3r

Recommended Posts

How can i get the content of the array?

Or is the array empty?

 

<?php

include "../../../config.php";
include "../../../lib.php";

$words = $_POST['wordids'];
print_r2($words);


for($i = 0; $i < count($words); $i++) {
echo "test";
$word = $words[i];
print_r2($word);

}

?>

 

Array

(

    [0] => Array

    [1] => Array

    [2] => Array

    [3] => Array

    [4] => Array

)

 

test

 

test

 

test

 

test

 

test

 

 

In case it helps, this is the form that sends the info:

 

<?php

include 'config.php';
include 'lib.php';

$db = dbConnect();

$words = getWords();

dbClose($db);


?>

<html>
<head>
	<title>Historer : Words</title>
</head>

<body>

	<?
	if(isset($_GET['removed'])) {
		?><div id="message">Removed <? echo $_GET['removed'] ?></div> <?	
	}
	?>

	<div id="container">
		<form method="post" action="inc/php/utils/word-exclude.php">
		<input type='submit' name='submit' value='Exclude Selected Words'>
			<table>
				<tr>
					<td>word</td>

				</tr>
				<?
				foreach($words as $word) {
					?>
					<tr>
						<td><input type="checkbox" name="wordids[]" value="<?=$word?>"><?=$word[word]?></td>
					</tr>
					<?
				}
				?>

			</table>
		</form>
	</div>
</body>

</html>

Link to comment
Share on other sites

foreach($words as $word) {
	print_r2($word);

}

 

Array

 

Array

 

Array

 

Array

 

Array

 

So those array's are empty right?

 

Is it possible what i want?

I use:

<input type="checkbox" name="wordids[]" value="<?=$word?>">

 

where $word is like: $word[id] and $word[word], so 2 values.

Link to comment
Share on other sites

foreach($words as $word) {
	print_r2($word);

}

 

Array

 

Array

 

Array

 

Array

 

Array

 

So those array's are empty right?

 

Is it possible what i want?

I use:

<input type="checkbox" name="wordids[]" value="<?=$word?>">

 

where $word is like: $word[id] and $word[word], so 2 values.

 

Those arrays aren't empty.  When it says array, you still have an array.

 

For your code specifically, to display those arrays, you'd need to do:

foreach( $words as $word )
{
     foreach ( $word as $_word )
     {
        print_r2($_word);
     }
}

 

But, to actually determine what is what, in your loop that creates the input boxes, I'd set the array key to have the words id stored in it.

 

$words = getwords();
foreach ( $words as $word )
{
  echo '<input type="checkbox" name="wordids['.$word['id'].']" value="'.$word.'">';
}

 

Then, when you print_r($_POST['wordids'] )

You'll have a list of all your words, with the key and it's corresponding value.

 

From there, you can loop the results and perform necessary queries.

 

 

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.