how to get mysql data from one table and pass it to another by php

-1

USE THE LAST PHP VERSION, Hello, how are you! I have a question! ... how do I get certain values from one table, to put it in another? ... example: I have a table products in this table I have ... "ID", "product", "description" and "value of the product "and already has several products registered in that data filled

the other table is called inventory ... this table has only "ID", "Product", "Quantity" and "sum of value" in sum of value if the product is worth $ 5 dollars and I have 2 products then in quantity leaves "2" and in sum of values are added how much it costs in this case will be "$ 10" dollars .... and this table I have to show in a

How can I do this? Please! thanks!

and another small question ... how do I get how many rows do I have in a table (only the number of rows) and I show it in a html tag, I'm trying this to see if a number comes out but no, I do not know how is done, I just want that echo to show me the number of records let's say an 8 and already

$statement = $conexion->prepare("SELECT count(*) FROM carrito");
$statement->execute();
$resultado = $statement->fetchAll();
echo $resultado;
    
asked by Jajo Go 16.11.2017 в 06:37
source

1 answer

-1

To obtain the number of records in a table is done in the way you mention, only that you need to assign a variable that will count those records. I share an example that I have so you can clarify your doubts:

$sql = "SELECT COUNT(*) as total FROM usuarios";
            $sentencia = $conexion -> prepare($sql);
            $sentencia -> execute();
            $resultado = $sentencia -> fetch();

            $totalUsuarios = $resultado['total'];

Notice that in total I assign the total of rows, you can print it in the following way:

echo $resultato['total'];
    
answered by 16.11.2017 в 06:49