Seleccionar BD por un select

14 views
Skip to first unread message

Danilo

unread,
Dec 16, 2013, 12:01:20 PM12/16/13
to programa...@googlegroups.com
hola chicos consulta
Quiero mostrar por intermendio de un select las bases de datos que contengan solo las tablas con el nombre de clientes
asi lo tengo pero no me muestra nada, si omito un pedazo de codigo me muestra todas la BD que tengo pero quiero que se vean solo las que tengan esa tabla
GRACIAS.

<html>
<head>

<title>Consulta a la base de datos</title>
</head>

<body>

<div align="center">
<select style='background:#7baec9;color:black' name='' maxlength='20'>
<?php           
$con = mysql_connect("localhost", "usuario_mysql", "contraseña_mysql") or die("No se pudo conectar: " . mysql_error());

            $sql="SHOW DATABASES";
            $res=mysql_query($sql,$con);

            while($reg=mysql_fetch_array($res))
            {
           
            $basedato = mysql_select_db($con,$reg[0]);
               
            $sql="SHOW TABLES LIKE 'clientes' ";
            $result=mysql_query($sql,$con);

            if ($reg=mysql_fetch_array($result))
                {
                    echo "<option value='".$reg[0]."'>".$reg[0]."</option>";
                }
             }

?>
</select>           
</div>       
</body>
</html>

Danilo

unread,
Dec 16, 2013, 1:22:35 PM12/16/13
to programa...@googlegroups.com
Ya lo solucione GRACIAS



<html>
<head>

<title>Consulta a la base de datos</title>
</head>

<body>

<div align="center">
<select style='background:#7baec9;
color:black' name='' maxlength='20'>

<?php           
        $con=mysql_connect("localhost", "usuario_mysql", "contraseña_mysql") or die ("No se pudo conectar: " . mysql_error());

        $sql="SHOW DATABASES";
        $res=mysql_query($sql,$con);

        while($reg=mysql_fetch_array($res)){
       
        $bd = mysql_select_db ($reg[0],$con) or die ("ERROR AL SELECCIONAR BASE DE DATOS: ".mysql_error());

       
        $sql="SHOW TABLES LIKE 'clientes'";
        $result=mysql_query($sql,$con);
               
        if ($registro=mysql_fetch_array($result)){ 
        echo "<option value='".$reg[0]."'>".$reg[0]."</option>";}
                   
        }

        ?>
</select>           
</div>       
</body>
</html>


Reply all
Reply to author
Forward
0 new messages