Select table in PHP by variable

1

I have my web connected to a database, and I select a table by putting it as it is called, but now I have divided by sections, and capable, what I want to show is in another table, and I want to change it directly from a variable: I give the example of how I have it and what I want to do:

$sql_dbpartidos = "SELECT * from equipos where id=0";

And I want to do something like this:

$sql_dbpartidos = "SELECT * from $sqlPrincipal where id=0";

And in $ sqlPrincipal I define the table I want to select, and so on all the pages, so I do not have to change one by one, is that understood?

Leaving it like this I get this error:

  

[11-Dec-2018 20:11:55 America / Argentina / Buenos_Aires] PHP Warning:   mysqli_fetch_array () expects parameter 1 to be mysqli_result, boolean   given in /home/adiccion/public_html/index.php on line 35

$sql_dbpartidos = "SELECT * from $sqlPrincipal where id=0";
$result_dbpartidos = mysqli_query($conexion,$sql_dbpartidos);
(linea 35) $rows_dbpartidos = mysqli_fetch_array($result_dbpartidos);
if($rows_dbpartidos){                          
  echo '<title>Adiccion Futbolera - Ver ' . $rows_dbpartidos['equipo_local'] .  ' vs ' . $rows_dbpartidos['equipo_visitante'] .  ' </title>';
    
asked by MatiST00 12.12.2018 в 00:05
source

1 answer

-1

It seems that you are indicating the variable inside the quotes.

Try this:

$sql_dbpartidos = "SELECT * from ".$sqlPrincipal." where id=0";
    
answered by 13.12.2018 в 14:07