PHP - Criação de tabelas a partir de banco de dados MYSQL

  • Autor Autor victorgalarza
  • Data de início Data de início
Tradução em andamento: em alguns minutos este tópico estará em português. Por enquanto, o conteúdo está no original em espanhol. Ver original
V

victorgalarza

Curioso
Usuário com poucas negociações! Use sempre o saldo do ForoBeta!
Buenos días
estoy desarrollando una consulta para poder extraer los datos de una BD a una tabla en PHP, mi pñroblema es que me muestra los datos pero se saltan en diferentes lineas, yo deseo que salga los resultados en una sola fila.

La consulta que estoy usando es:

class Buscadordeta
{
private $busqueda=array();

public function buscardeta()
{
//print_r($_GET);exit;
$query = "SELECT D.codcon, A.MESINI,B.MESFIN, D.abrcon, C.des_corta, A.importe FROM plutimcp A
inner join plmovmae B
on A.libele=B.libele and A.mesini=B.mesini
inner join pltabmcp C
on A.codcon=C.concepto
inner join pltabcon D
on C.codcon=D.codcon
WHERE A.tipo BETWEEN 1 and 4 and B.nombre like '%".$_GET['s']."%'
group by A.mesini, D.codcon
order by A.MESINI;";
/*$res = mysql_query($query,Conectar::con() or die("Error en: $busqueda: " . mysql_error()));*/
$res = mysql_query($query,Conectar::con()) or die("Error en: $query: " . mysql_error());
while ($reg=mysql_fetch_assoc($res))
{
$this->busqueda[] = $reg;
}
return $this->busqueda;
}

}

Y para mostrar los datos el siguiente codigo

<table border="2">
<tr>
<th width="50px">INICIO</th>
<th width="50px">REM.BAS 1001</th>
<th width="50px">R.REUNIF 1002</th>
<th width="50px">BON.PER 1003</th>
<th width="50px">BON.FAMI 1004</th>
<th width="50px">TRA.HOMO 1005</th>
<th width="50px">COST.VID 1006</th>
<th width="50px">MOV.REF 1007</th>
<th width="50px">BE051.91 1008</th>
<th width="50px">10.23%+3 1009</th>
<th width="50px">REM ANTE 1010 </th>
<th width="50px">ICAJ3.3% 1011 </th>
<th width="50px">A.J.SUP 1012</th>
<th width="50px">DS040.92 1014</th>
<th width="50px">DL.25671 1015</th>
<th width="50px">DL.25697 1016</th>
<th width="50px">BE.81.93 1017</th>
<th width="50px">BE.19.94 1018</th>
<th width="50px">DU.80.94 1019</th>
<th width="50px">D.118.94 1020</th>
<th width="50px">DU090.96 1021</th>
<th width="50px">DU073/97 1022</th>
<th width="50px">LEY25303 1023</th>
<th width="50px">AS.COM.T 1024</th>
<th width="50px">ART.18 1025</th>
<th width="50px">PEN.PROV 1026</th>
<th width="50px">PEN.DOC 1027</th>
<th width="50px">PEN.GRA 1028</th>
<th width="50px">FUN.SAL 1029</th>
<th width="50px">DL.817 1030</th>
<th width="50px">DU011/99 1031</th>
<th width="50px">DU037.94 1038</th>
<th width="50px">AGUINALD 1054</th>
<th width="50px">REINTEGR 1160</th>
<th width="200px">TOTAL</th>
</tr>
<?php
//COMPROBAMOS SI HAY REGISTROS EN LA BUSQUEDA, SI NO LOS HAY, MOSATRAMOS UN MENSAJE DICIENDO QUE NO HAY RESULTADOS, EN OTRO CASO, MOSTRAMOS LOS RESULTADOS
if(count($buscamedeta)==0)
{
echo "<h2>No hay resultados para su búsqueda...</h2>";
}else{
for($i=0;$i<sizeof($buscamedeta);$i++)
{
?>
<tr>
<td align="center">
<?php echo $buscamedeta[$i]["MESINI"] ."/". $buscamedeta[$i]["MESFIN"]?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1001")
{
echo $buscamedeta[$i]["importe"];
}

?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1002")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1003")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1004")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1005")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1006")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1007")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1008")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1009")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1010")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1011")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1012")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1014")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1015")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1016")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1017")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1018")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1019")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1020")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1021")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1022")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1023")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1024")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1025")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1026")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1027")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1028")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1029")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1030")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1031")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1038")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1054")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
<td align="center">
<?php
if ($buscamedeta[$i]["codcon"]=="1160")
{
echo $buscamedeta[$i]["importe"];
}
?>
</td>
</tr>

<?php
}
}
?>


</table>

Pero me muestra de la siguiente manera y deseo que todo sea en una sola fila relacionado por la columna inicio

resultado.webp
 
Foi útil? Participe da conversa

Com sua conta grátis você pode responder, mandar mensagem privada ao autor e comprar com Saldo retido: o pagamento é liberado quando você recebe o combinado.

Leva 30 segundos · você volta a este tópico ao terminar
Usa PDO es mejor y orientado a objetos... y usa foreach en vez de for
 
haz un ejemplo en excel de como deberia de salir lo que quieres, para poder entenderte y asi poder ayudarte.
favor tu codigo coloca dentro de las etiquetas de php para poder tener mejor formato

Inserir CODE, HTML ou PHP:
[*PHP]AQUI TU CODIGO[/*PHP]

sin los astericos obviamente.
 
Última edição:
Voltar
Topo