Failed to create array

Asked

Viewed 56 times

-2

I’m using php 5.3 with Postgree on a project I’m working on.
That way I have to use the array() and not the [ ].
I have a table that I need to send by email but when sending only the last record is coming. I need to send this table by e-mail with all lines.
I am trying to pass the values of the variable to an array but it shows all values in the Index, zero as image.
I am using a while. I would like to fix this without changing the current structure that is by while and not by for.
inserir a descrição da imagem aqui

    $c = 0;
       while ($row = pg_fetch_array($res))                          
    {
      $c++;

    $sql1 = "
    select a.aux_nomecompltaxon from jabot.testemunho t,jabot.arvoretaxon a,jabot.determinacao d
    where a.codarvtaxon = d.codarvtaxon
    and d.coddeterminacao = t.ultimadeterm
    and t.codtestemunho = '".$row['codtestemunho']."'
    ";
    $res1 = pg_exec($conn,$sql1);
    $determinacao = pg_fetch_array($res1);

    ?>
    <tr>
        <td> 
            <input type="checkbox" name="iditemguiaremessa[]" id="iditemguiaremessa" value="<?php echo $row["iditemguiaremessa"];?>" />
        </td>
    <td> 
        <?php echo $c;?>
    </td>
        <td> 
          <?php                                 
    $array = array(
    $row['codtestemunho'] ,
    );
    print_r($array);
    ?>                                    
    <input type="hidden" name="edtcodigobarra" value="<?php echo $array[0]; ?>" >

    </td>

   }
  • 1

    Your question is very confusing and has no scope. I couldn’t identify what the problem is. What do you want to do? Do you want to re-negotiate the array? Want to send an email?

  • 1

    Thanks for the Feedback. I will edit to make it clear.

  • See if it looks better, @Cypherpotato?

  • What is the structure of this $res? Puts the var_dump of it for us to see.

1 answer

1


guy this here

$array = array( $row['codtestemunho'] , );

is the same as this

$array=$row['codtestemunho']

and how you want to send the array ocm all Rows the right one would be this:

$array[]=$row['codtestemunho']

Why with each iteration ( loop ) you add one more item within the variable $array.

and in case you need to send by email can do something like this:

$result = implode(",",$array);

of the one echo in the $result then for you to see.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.