Jump to content

little help with array


sheriff

Recommended Posts

little problem ...

 

this textfield is in a table what is generated by php from mysql.

 

after is generated, i enter in this textfield  numbers what is the quantity of each product.

 

the data is sent by the script you tell'd me, but only the last number in the table.

 

:(

 

exemple:

 

<table bgcolor="#000000" cellpadding="1" cellspacing="1" width="78%">
<tr>
    <td width="28%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Nume</strong></font></td>
    <td width="60%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Descriere</strong></font></td>
    <td width="5%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>UM</strong></font></td>
    <td width="7%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Cant</strong></font></td>
</tr>
<tr>
    <td bgcolor="#DDD7CC"><font size="3">product 1</font></td>
    <td bgcolor="#DDD7CC"><font size="3">size and stuff</font></td>
    <td align=center bgcolor="#DDD7CC"><font size="3">buc</font></td>
    <td align=right bgcolor="#DDD7CC"><font size="3"></font>3</td>
</tr>
<tr>
    <td bgcolor="#DDDAD4"><font size="3">product 2</font></td>
    <td bgcolor="#DDDAD4"><font size="3">size and stuff</font></td>
    <td align=center bgcolor="#DDDAD4"><font size="3">buc</font></td>
    <td align=right bgcolor="#DDDAD4"><font size="3"></font>3</td>
</tr>
</table>

 

 

<table bgcolor="#000000" cellpadding="1" cellspacing="1" width="78%">

<tr>

    <td width="28%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Nume</strong></font></td>

    <td width="60%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Descriere</strong></font></td>

    <td width="5%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>UM</strong></font></td>

    <td width="7%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Cant</strong></font></td>

</tr>

<?php foreach($_POST['cant'] as $key => $value){ ?><tr>

    <td bgcolor="#DDD7CC"><font size="3">product 1</font></td>

    <td bgcolor="#DDD7CC"><font size="3">size and stuff</font></td>

    <td align=center bgcolor="#DDD7CC"><font size="3">buc</font></td>

    <td align=right bgcolor="#DDD7CC"><font size="3">$value</font>3</td>

</tr>

<? } ?>

</table>

 

 

it's work now, but because I already have a foreach he double the table,

 

if(isset($_POST)){

          if(count($_POST['check'])){

            $list_selected = "";

            foreach($_POST['check'] as $key => $ids){

                  $list_selected .= $ids .",";

            }

foreach($_POST['cant'] as $key => $value)

            $list_selected = substr($list_selected,0,strlen($list_selected)-1);

            // This will give ur selected ids like this 100,203,125,123

          }else{

            $list_selected = "-1";

          }

}

 

how can i add this ($_POST['cant'] as $key => $value) too ?

 

thanks

so ...

I have

 

if(isset($_POST)){
          if(count($_POST['check'])){
            $list_selected = "";
            foreach($_POST['check'] as $key => $ids){
                   $list_selected .= $ids .",";
            }
            $list_selected = substr($list_selected,0,strlen($list_selected)-1);
            // This will give ur selected ids like this 100,203,125,123
}
	  }else{
            $list_selected = "-1";
          } 
}

 

how i implement your code ?

if(isset($_POST)){
          if(count($_POST['check'])){
            $list_selected = "";
            for($i=0;$i<count($_POST['check']);$i++){
            echo $_POST['check'][$i];
            echo $_POST['cant'][$i];
}

            $list_selected = substr($list_selected,0,strlen($list_selected)-1);
            // This will give ur selected ids like this 100,203,125,123
}

 

in this way don't work :(

 

Sorry ... i'm noob :(

if count for $_POST['check'] and $_POST['cant'] are same then

<tr>

    <td width="28%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Nume</strong></font></td>

    <td width="60%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Descriere</strong></font></td>

    <td width="5%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>UM</strong></font></td>

    <td width="7%" bgcolor="#000000" align="center"><font color="#FFFFFF" size="3"><strong>Cant</strong></font></td>

</tr>

 

<?php for($i=0;$i<count($_POST['check']);$i++){ ?>

<tr>

    <td bgcolor="#DDD7CC"><font size="3">product 1</font></td>

    <td bgcolor="#DDD7CC"><font size="3">size and stuff</font></td>

    <td align=center bgcolor="#DDD7CC"><font size="3"><?php echo $_POST['check'][$i];?></font></td>

    <td align=right bgcolor="#DDD7CC"><font size="3"><?php echo $_POST['cant'][$i];?></font>3</td>

</tr>

<?php } ?>

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.