Foros del Web » Programando para Internet » PHP »

CONECTAR Sql y PHP y mostar los valores en una tabla

Estas en el tema de CONECTAR Sql y PHP y mostar los valores en una tabla en el foro de PHP en Foros del Web. Hola necesito una ayuda, tengo el siguiente codigo PHP que se conecta con SQL y Funciona ... Al fin <?php $conexion_sqlserver = mssql_connect("servidor","nombreusuario","passw"); mssql_select_db("base de ...
  #1 (permalink)  
Antiguo 14/05/2008, 16:51
 
Fecha de Ingreso: febrero-2007
Mensajes: 13
Antigüedad: 17 años, 3 meses
Puntos: 0
CONECTAR Sql y PHP y mostar los valores en una tabla

Hola necesito una ayuda, tengo el siguiente codigo PHP que se conecta con SQL y Funciona ... Al fin

<?php
$conexion_sqlserver = mssql_connect("servidor","nombreusuario","passw");
mssql_select_db("base de dato");
$consulta_sql = mssql_query("Exec Sp_EstadoCtrTiempo '', 5, 2008",$conexion_sqlserver);
while ($registro = mssql_fetch_array($consulta_sql))
{
print "------------------------------------------------------------"."<br>";
echo "Departamento:".$registro[0]."<br>";
echo " Rut:".$registro[1];
echo "-".$registro[2]."<br>";
echo " Nombre:".$registro[3]."<br>";
echo " Apellido:".$registro[4]."<br>";
echo " Anexo:".$registro[5]."<br>";
echo " Numero Control:".$registro[6]."<br>";
echo " Mes:".$registro[7]."<br>";
echo " Año:".$registro[8]."<br>";
echo " Tipo Quincena:".$registro[9]."<br>";
echo " Lineas:".$registro[10]."<br>";
echo " Total Horas:".$registro[11]."<br>";
}
mssql_close($conexion_sqlserver);
?>


Y TODO ME FUNCIONA DE MARAVILLA... pero quiero que se vea un poquito mejor los campos obtenido quiero almacenarlos en tablas.

esto es lo que hice:

<?php
<?php
$conexion_sqlserver = mssql_connect("servidor","nombreusuario","passw");
mssql_select_db("base de dato");
$consulta_sql = mssql_query("Exec Sp_EstadoCtrTiempo '', 5, 2008",$conexion_sqlserver);
while ($registro = mssql_fetch_array($consulta_sql))
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000">
<table width="100%" border="1" cellspacing="1" bordercolor="#666666">
<tr align="center" background="a.jpg">
<td><font color="#000000">Departamento</font></td>
<td><font color="#000000">Rut</font></td>
<td><font color="#000000">-</font></td>
<td><font color="#000000">Nombre</font></td>
<td><font color="#000000">Apellido</font></td>
<td><font color="#000000">Numero de Control</font></td>
<td><font color="#000000">Mes</font></td>
<td><font color="#000000">año</font></td>
<td><font color="#000000">Tipo</font></td>
<td><font color="#000000">lineas</font></td>
<td><font color="#000000">Total Horas</font></td>
</tr>
<?php do { ?>
<tr>
<td><?php $registro[0]; ?></td>
<td><?php echo $registro[1]; ?></td>
<td><?php echo $registro[2]; ?></td>
<td><?php echo $registro[3]; ?></td>
<td><?php echo $registro[4]; ?></td>
<td><?php echo $registro[5]; ?></td>
<td><?php echo $registro[6]; ?></td>
<td><?php echo $registro[7]; ?></td>
<td><?php echo $registro[8]; ?></td>
<td><?php echo $registro[9]; ?></td>
<td><?php echo $registro[10]; ?></td>
<td><?php echo $registro[11]; ?></td>
</tr>
<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset2);
?>

una ayuda porfa
  #2 (permalink)  
Antiguo 14/05/2008, 17:01
 
Fecha de Ingreso: febrero-2007
Mensajes: 13
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

NO SE SI SEA NECESARIO PERO ME DA EL SIGUIENTE ERROR:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\conexion\nueva.php on line 44
Departamento Rut - Nombre Apellido Numero de Control Mes año Tipo lineas Total Horas (ESTA ES LA TABALA)


Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\conexion\nueva.php on line 49
  #3 (permalink)  
Antiguo 14/05/2008, 17:01
Avatar de trasgukabi  
Fecha de Ingreso: septiembre-2004
Mensajes: 2.749
Antigüedad: 19 años, 8 meses
Puntos: 18
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

Código PHP:
<?php
$conexion_sqlserver 
mssql_connect("servidor","nombreusuario","passw");
mssql_select_db("base de dato");
$consulta_sql mssql_query("Exec Sp_EstadoCtrTiempo '', 5, 2008",$conexion_sqlserver);

?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000">
<table width="100%" border="1" cellspacing="1" bordercolor="#666666">
<tr align="center" background="a.jpg">
<td><font color="#000000">Departamento</font></td>
<td><font color="#000000">Rut</font></td>
<td><font color="#000000">-</font></td>
<td><font color="#000000">Nombre</font></td>
<td><font color="#000000">Apellido</font></td>
<td><font color="#000000">Numero de Control</font></td>
<td><font color="#000000">Mes</font></td>
<td><font color="#000000">año</font></td>
<td><font color="#000000">Tipo</font></td>
<td><font color="#000000">lineas</font></td>
<td><font color="#000000">Total Horas</font></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $registro[0]; ?></td>
<td><?php echo $registro[1]; ?></td>
<td><?php echo $registro[2]; ?></td>
<td><?php echo $registro[3]; ?></td>
<td><?php echo $registro[4]; ?></td>
<td><?php echo $registro[5]; ?></td>
<td><?php echo $registro[6]; ?></td>
<td><?php echo $registro[7]; ?></td>
<td><?php echo $registro[8]; ?></td>
<td><?php echo $registro[9]; ?></td>
<td><?php echo $registro[10]; ?></td>
<td><?php echo $registro[11]; ?></td>
</tr>
<?php } while ($registromysql_fetch_assoc($consulta_sql)); ?>
</table>
</body>
</html>
<?php
mysql_free_result
($registro);
?>
deja ya el dreamweaver...
  #4 (permalink)  
Antiguo 14/05/2008, 17:10
 
Fecha de Ingreso: junio-2007
Ubicación: por ahi
Mensajes: 262
Antigüedad: 16 años, 10 meses
Puntos: 4
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

lo que no me queda claro de tu codigo y deberies arreglar es:

mssql_connect para conectar

y

mysql_fetch_assoc

para recorrer el arreglo

Estas mezclando codigos. Define bien a cual Base de datos te estas conectando. Ese es el principal Error ( Mysql o Mssql)
__________________
Hernando Saenz Sanchez
  #5 (permalink)  
Antiguo 14/05/2008, 17:12
Avatar de trasgukabi  
Fecha de Ingreso: septiembre-2004
Mensajes: 2.749
Antigüedad: 19 años, 8 meses
Puntos: 18
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

coño! ni me habia fijado que la conexión era mssql y el recorrido mysql, jajaja
  #6 (permalink)  
Antiguo 14/05/2008, 17:13
 
Fecha de Ingreso: febrero-2007
Mensajes: 13
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

Estimado gracias por la pronta respuesta, pero no se donde esta el problema aun sigo con el error en las mismas lineas... LA BASE DE DATOS ES UNA MSSQL, conectadola a mysql no tengo problemas.

CUAL EDITOR ME RECOMIENDAS
  #7 (permalink)  
Antiguo 15/05/2008, 07:45
 
Fecha de Ingreso: febrero-2007
Mensajes: 13
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

hice estas modificaciones, pero aun sigo con errores, no se ya que mas hacer, necesito porner en tabla los resultados que me da, como les dije en el primer tema la conexion numero 1 me conecta pero me muestra los datos hacia a bajo y desordenados.


<?php
$conexion_sqlserver = mssql_connect("200.29.18.66","sa","mzsqlserver");
mssql_select_db("Empresa");
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000">
<table width="100%" border="1" cellspacing="1" bordercolor="#666666">
<tr align="center" background="a.jpg">
<td><font color="#000000">Departamento</font></td>
<td><font color="#000000">Rut</font></td>
<td><font color="#000000">-</font></td>
<td><font color="#000000">Nombre</font></td>
<td><font color="#000000">Apellido</font></td>
<td><font color="#000000">Numero de Control</font></td>
<td><font color="#000000">Mes</font></td>
<td><font color="#000000">año</font></td>
<td><font color="#000000">Tipo</font></td>
<td><font color="#000000">lineas</font></td>
<td><font color="#000000">Total Horas</font></td>
</tr>

<?php
$consulta_sql = mssql_query("Exec Sp_EstadoCtrTiempo '', 5, 2008",$conexion_sqlserver);
while ($registro = mssql_fetch_array($consulta_sql))

do {
?>

<tr>
<td><?php $registro[0]; ?></td>
<td><?php echo $registro[1]; ?></td>
<td><?php echo $registro[2]; ?></td>
<td><?php echo $registro[3]; ?></td>
<td><?php echo $registro[4]; ?></td>
<td><?php echo $registro[5]; ?></td>
<td><?php echo $registro[6]; ?></td>
<td><?php echo $registro[7]; ?></td>
<td><?php echo $registro[8]; ?></td>
<td><?php echo $registro[9]; ?></td>
<td><?php echo $registro[10]; ?></td>
<td><?php echo $registro[11]; ?></td>
</tr>
<?php
}
while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset2);
?>
  #8 (permalink)  
Antiguo 15/05/2008, 07:49
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

me podrias explicar q es lo q mas o menos intentas hacer????
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #9 (permalink)  
Antiguo 15/05/2008, 08:49
 
Fecha de Ingreso: febrero-2007
Mensajes: 13
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: CONECTAR Sql y PHP y mostar los valores en una tabla

es mostrar los datos que tengo en una tabla de sql y ordenarlos en filas y columnas.

EJEMPLO:

------------------------------------------------------------
Departamento:
Rut:1
Nombre:P
Apellido:P
Anexo:
Numero Control:
Mes:
Año:
Tipo Quincena:
Lineas:0
Total Horas:
------------------------------------------------------------
Departamento:
Rut:1
Nombre:M
Apellido:C
Anexo:
Numero Control:
Mes:
Año:
Tipo Quincena:
Lineas:0
Total Horas:
------------------------------------------------------------

Esto me sale con el primer codigo que publique, ahora necesito mostrar estos datos en una tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:18.