Not all data is being saved in the array through mysqli_fetch_array() function when I try to echo each index. I want to store all table names inside of an array variable called $tablas So I'm trying to gather all the table names using the mysqli_fetch_array(). I have 4 tables stored in the datable so I was using a print_r() but it was only showing for the index of 0, then I tried with a var_dump() but did the same. So I wanted to find out if table names are actually being saved into the $table array so then I tried with using echo instead for each index in the array as shown below but only is working for index 0 others seem not to exist. What is causing this?
<?php
$conexion = mysqli_connect("localhost","root","","capacitacion");
$consulta = "SHOW TABLES FROM capacitacion";
$resultado = mysqli_query($conexion, $consulta);
if($resultado){
$tablas = mysqli_fetch_array($resultado);
echo $tablas[0];
echo $tablas[1];
echo $tablas[2];
}
else{
echo 'error';
}
?>
mysqli_fetch_array()only returns a single row at a time.var_dump($tablas)to debug the structure of your array, you will see it is compose of many items (array themselves), so you probably have to loop overtablasif you want to handle this case.mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface where missing a singleican cause trouble. Example:$db = new mysqli(…)and$db->prepare("…")The procedural interface is an artifact from the PHP 4 era and should not be used in new code.