How to create a table in php?

2

I am trying to create a program that calculates discounts since I have the code but I do not understand how to do it in the form of a table k exit this way try to use tags tr and td but the variables do not detect them.

Prod 1   500    100  
Prod 2   300    100  
Prod 3   200    100

Subtotal  
DESCUENTO XX     XX  
TOTAL     XX     XX

This is my code:

<?php
echo"<tr>"
$a=500;
$b=300;
$x=200;    
$desc=0.1;
$desc2=0.05;
$subtotal=$desc * $a;
$subtotall=$desc2 * $b;
</tr>";
</table";

$total;

if($a>500)
{
echo "Se te desconto el 10%";
    echo "El subtotal es " .$subtotal;


    echo "el total es".($a- $subtotal );


}

if($b<500)
{
    echo "Se te desconto el 5%";
    echo "el subtotal es " .($subtotall);
    echo "el total es " .($b - $subtotall);



    }

?>
    
asked by wdwd 20.02.2018 в 18:36
source

1 answer

1

It's the same structure of an HTML table:

<table>
  <tr>
    <th>Nombre</th>
    <th>Apellido</th>
  </tr>
  <tr>
    <td>Ana</td>
    <td>Ortiz</td>
  </tr>
  <tr>
    <td>Pedro</td>
    <td>Duarte</td>
  </tr>
</table>

But in php, every element or set of elements is displayed with PHP echo.

$nombre1   = "Adriana";
$apellido1 = "Ortiz";
$arr = array("Pedro", "Duarte");

echo "<table>";
echo "<tr>";
echo "  <th> Nombre  </th>";
echo "  <th> Apellido </th>";
echo "</tr>";
echo "<tr>";
echo "<td> " . $nombre1 . "</td>";
echo "<td> " . $apellido1 . "</td>";
echo "</tr>";
echo "<tr>  <td>" . $arr[0] . "</td> <td>" . $arr[1] ."</td>  </tr>" ;
echo "</table>";
    
answered by 20.02.2018 / 20:25
source