1

My table is not filling all the data i need. Is missing some columns be filled with form multiple. The column where the th is Renault need to be the same for all the rest are empty.

In next picture, you can see when i select options in dynamic selectbox multiple and submit, is only filling in the first column when the expectable is fill all the columns selected.

enter image description here

Next is the code where is giving the value of the select box multiple.

if ($consulta !=0) {
}//
else{
    echo "";
}

@$s1= $_POST['s1'];
if( is_array($s1)){
    while (list ($key, $val) = each ($s1)) {

    }
}//
else{
    echo "";
}
/////////////////
@$s2= $_POST['s2'];
if( is_array($s2)){

?>

Next is the code where data is filled in the html table. That line of code<td align=\"center\" bgcolor='FFFFFF'> need to be associate the result of: <?php echo "$key => $val1\n";?> to which form:

The result of <?php echo "$key => $val1\n";?>

0 => Renault 1 => Opel 2 => Mercedes 3 => Audi 

The expected output is missing.

Renault

<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">

Opel

<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">

Mercedes

<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">

Audi

<form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">

That is dynamic, will get the values from mysql database and i can select which i want.

There is all the table where is filled the data. Static and dynamic.

    <table>
     <tbody>
        <tr>
            <th>Parametro:</th>

    <?php 
        while (list($key, $val1) = each ($s2)) { 
    ?>

            <th><?= htmlspecialchars($val1, ENT_HTML5 | ENT_COMPAT, 'UTF-8') ?></th>
    <?php 
            echo "$key => $val1\n";
    ?>
    <?php 
        } 
    ?>

The values down of the Parametro:

    {
        echo("<tr>
        <td align=\"center\" bgcolor='FFFFFF'>$utilizador</td>

     <td align=\"center\" bgcolor='FFFFFF'>

    <form onsubmit=\"return validate();\" id=\"teste\" method=\"post\" action=\"teste.php\">


    ");

Code from the form:

$con = mysqli_connect( "localhost","root","","teste" ); // ◄■ CONNECT TO DATABASE.
$dat_menuid = mysqli_query( $con,"SELECT * FROM menu WHERE menuId = '".$menuId."'"  ) // ◄■ MENUIDs.
                      or die( mysqli_error($con) );
        $con1 = mysqli_connect( "localhost","root","","teste" ); // ◄■ CONNECT TO DATABASE.           
            $idtem = mysqli_query($con1, "SELECT MAX(id_tem) as id_tem FROM tem")        
                       or die( mysqli_error($con) );


// Print out result
while($row = $idtem->fetch_assoc())
   $toEcho = $row["id_tem"];

//echo $toEcho;

$toEchosave = $toEcho + 1;
$_SESSION['myvar'] = $toEchosave;




$options = array( "0.00","0.05","0.10","0.15","0.20","0.25","0.30","0.35","0.40","0.45","0.50","0.55","0.60","0.65","0.70","0.75","0.80","0.85","0.90","0.95","1" ); // ◄■■ OPTIONS ARE STATIC (ALWAYS THE SAME).
while ( $row_menuid = mysqli_fetch_array( $dat_menuid ) ) // ◄■ DISPLAY <SELECT>s.


{ echo "<select class='sumselect' name='corp_resp&{$row_menuid['menuId']}&{$_SESSION['UtilizadorID']}&{$dateTime}&{$toEchosave}' multiple>"; // ◄■■ CORP_RESP&1,CORP_RESP&2.

    foreach ($options as $opt)
                echo "<option value='$opt'>$opt</option>\n";
            echo "</select>\n";
        } ?>
    </form>
    </td>

  </tr>
  <?php } ?>


 <?php }
   }
   }

   ?>
 <div id='sum'></div>
 <br><br><br>


</tbody>
</table>
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Mar 15 '17 at 10:33
  • 1
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Mar 15 '17 at 10:33
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Mar 15 '17 at 10:34
  • You only need to connect to the database ONCE per script, not every time you run a query – RiggsFolly Mar 15 '17 at 10:35
  • Can you give a example please what you mean? @RiggsFolly – Christophe Costa Mar 15 '17 at 10:39
  • 2
    The code is just a horrible mess. I have no idea how you know what its doing and I have not got the desire to find out. – RiggsFolly Mar 15 '17 at 10:44
  • Ok. Thank you anyway. – Christophe Costa Mar 15 '17 at 10:46

1 Answers1

1

follow this code

<?php
$sql = "SELECT * FROM menu WHERE $id = menuIdPai  ORDER BY menuId ";

$consulta = mysql_query($sql);

    while ($mostrar = mysql_fetch_array($consulta)) {

    $id = $mostrar['menuId'];
    $utilizador = $mostrar['menuNome'];
    ?>

    <tr>
        <td align=\"center\" bgcolor='FFFFFF'>Test1</td>

        <td align=\"center\" bgcolor='FFFFFF'>Test2</td>
        <td align=\"center\" bgcolor='FFFFFF'>Test3</td>

        <td align=\"center\" bgcolor='FFFFFF'>Test4</td>
    </tr>
    <?php
}

?>

this is main format if work then update your code . you add 2 td but your main th 4 so need 4 td

your this tag not close

 <td align="center" bgcolor='FFFFFF'>

<form onsubmit="return validate();" id="teste" method="post" action="teste.php">

so close this in your script

    <div id='sum'></div>
   <br><br><br>


 </form>
</td>

 </tr>

move this code before end loop

      foreach ($options as $opt)
                echo "<option value='$opt'>$opt</option>\n";
            echo "</select>\n";
        } ?>
    </form>
    </td>

  </tr>
  <?php } ?>


 <?php }
   }
   }

   ?>
 <div id='sum'></div>
 <br><br><br>


</tbody>
</table>
Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43