why does it give an error on the PhP line?

0

The code is the following one I am doing after consulting from mySQL.

<?php
include_once "conex.php";

$resultado1 = mysqli_query($conexion, "SELECT nombre_esp,cantidad FROM sr_productos WHERE id = (SELECT id_producto1 FROM sr_escalas_detalle WHERE orden = 1 ORDER BY Orden ASC LIMIT 1)");$result1 = mysqli_fetch_array ($resultado1);
print "$result1[0]"
$resultado2 = mysqli_query($conexion, "SELECT nombre_esp,cantidad FROM sr_productos WHERE id = (SELECT id_producto2 FROM sr_escalas_detalle WHERE orden = 2 ORDER BY Orden ASC LIMIT 1)");$result2 = mysqli_fetch_array ($resultado2);
print "$result2[0]"
$resultado2 = mysqli_query($conexion, "SELECT nombre_esp,cantidad FROM sr_productos WHERE id = (SELECT id_producto3 FROM sr_escalas_detalle WHERE orden = 3 ORDER BY Orden ASC LIMIT 1)");$result3 = mysqli_fetch_array ($resultado3);
print "$result3[0]"
?>

If I put only print the ( print "$ result1 [0]" ) commented on the print "$ result2 [0]" and the print " $ result3 [0] " with your queries. he does it very well but when I place or better said, I decompose from the second line onwards, I get an error. Does anyone help me? I think that according to my knowledge the line "seems" fine but the error comes out when adding the second query.

the error is as follows:

Parse error: syntax error, unexpected T_VARIABLE in C: \ xampp \ htdocs \ config \ show.php on line 7

PS: ALL queries and subqueries CAN be altered, because ALL have been tested and tested the problem is not from MySQL is from PhP that is not seen where the variable value waits.

    
asked by Juan Carlos Villamizar Alvarez 26.11.2018 в 23:08
source

2 answers

0

The error was easier only had to detail that a variable was repeated for that reason to error.

$resultado1 = mysqli_query($conexion, "SELECT nombre_esp,cantidad FROM sr_productos WHERE id = (SELECT id_producto1 FROM sr_escalas_detalle WHERE orden = 1 ORDER BY Orden ASC LIMIT 1)");$result1 = mysqli_fetch_array ($resultado1);
print "$result1[0]"
**$resultado2** = mysqli_query($conexion, "SELECT nombre_esp,cantidad FROM sr_productos WHERE id = (SELECT id_producto2 FROM sr_escalas_detalle WHERE orden = 2 ORDER BY Orden ASC LIMIT 1)");$result2 = mysqli_fetch_array ($resultado2);
print "$result2[0]"
**$resultado2** = mysqli_query($conexion, "SELECT nombre_esp,cantidad FROM sr_productos WHERE id = (SELECT id_producto3 FROM sr_escalas_detalle WHERE orden = 3 ORDER BY Orden ASC LIMIT 1)");$result3 = mysqli_fetch_array ($resultado3);
print "$result3[0]"
?>

When executing $ result2, it clashed with the previous sentence. the commas and dots vote as well but the complement even if you put the print to give that error. that is why each variable must be unique in php

    
answered by 04.12.2018 / 16:27
source
2

They are not being included ";" after each print

print "$result1[0]"; // ; para fin de sentencia

It is necessary to include ";" after each sentence. Although it is optional (but recommendable) for the last sentence of the file.

It is also recommended that each line of code be in its own line for more clarity, so the sentence:

$result1 = mysqli_fetch_array ($resultado1);

It would be more appropriate in its own line

    
answered by 27.11.2018 в 10:20