1

table result vardumb result

is there anyway to display my data to fit correctly on cells ?

page1.php

<td><input type='hidden' name='nom[]' value='".$row['nom']." ".$row['prenom']."'/></td>

page2.php

$idArrays = array($_POST['nom'], $_POST['montant'], $_POST['disponible_fiche'],$_POST['date_f'],$_POST['observation'] );

   foreach ($idArrays as $idArray) {

        echo '<tr>';
            foreach ($idArray as $key ) {

               echo '<td>'.$key.'</td>';

           }
        echo '</tr>';

 }
2
  • 6
    You didn't mention what the problem is .. Commented May 24, 2016 at 10:06
  • how did you get the value? from database? if so share your MySQL code to fetch the result. Better make changes in result format so the for loop will automatically arrange the row columns. Commented May 24, 2016 at 10:24

1 Answer 1

1

If you make your $idArray a little bit different it works. If all the arrays have the same length you can use array_map to create a new array in the right format.

$idArrays = array_map(null,$_POST['nom'], $_POST['montant'], $_POST['disponible_fiche'],$_POST['date_f'],$_POST['observation'] );

If some of the arrays are shorter, they will be padded with nulls to the length of the longest.

You can use your normal foreach then.

foreach ($idArrays as $idArray) {
    echo '<tr>';
    foreach ($idArray as $key ) {
        echo '<td>'.$key.'</td>';

    }
    echo '</tr>';
 }

Explanation:

This method "zips" the arrays together, rather than making an array of the original arrays.

Example:

<?php
$a = array("1","2");
$b = array("a","b");
$c = array("!","§");
print_r(array_map(null,$a,$b,$c));
print_r(array($a,$b,$c));
?>

Outputs:

with array_map:

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => a
            [2] => !
        )

    [1] => Array
        (
            [0] => 2
            [1] => b
            [2] => §
        )

)

with normal array declaration:

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
        )

    [1] => Array
        (
            [0] => a
            [1] => b
        )

    [2] => Array
        (
            [0] => !
            [1] => §
        )

)
Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much you saved my day really appreciate it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.