place table next to other table in php

Asked

Viewed 473 times

0

I have these two loops :

$result = mysqli_query($conn, $sql);

$result1 = mysqli_query($conn, $sql1);

$tabela1 .= '<div style="float: center" table align="center">';

$tabela1 .= '<table border="5">';

$tabela1 .= '<tr>';

$tabela1 .='<thead>';

$tabela1 .= '<tr>';

$tabela1 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela1 .= '<th style="width:40px; text-align: center"><strong>Pequeno Almoço</strong></th>';

$tabela1 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela1 .= '</tr>';

$tabela1 .='</thead>'; 

$tabela1 .='<tbody>';

$tabela2 .= '<div style="float: center" table align="center">';

$tabela2 .= '<table border="5">';

$tabela2 .= '<tr>';

$tabela2 .='<thead>';

$tabela2 .= '<tr>';

$tabela2 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela2 .= '<th style="width:40px; text-align: center"><strong>Almoço</strong></th>';

$tabela2 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela2 .= '</tr>';

$tabela2 .='</thead>'; 

$tabela2 .='<tbody>';

$tabela3 .= '<div style="float: center" table align="center">';

$tabela3 .= '<table border="5">';

$tabela3 .= '<tr>';

$tabela3 .='<thead>';

$tabela3 .= '<tr>';

$tabela3 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela3 .= '<th style="width:40px; text-align: center"><strong>Almoço Dieta</strong></th>';

$tabela3 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela3 .= '</tr>';

$tabela3 .='</thead>'; 

$tabela3 .='<tbody>';

$tabela4 .= '<div style="float: center" table align="center">';

$tabela4 .= '<table border="5">';

$tabela4 .= '<tr>';

$tabela4 .='<thead>';

$tabela4 .= '<tr>';

$tabela4 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela4 .= '<th style="width:40px; text-align: center"><strong>Lanche</strong></th>';

$tabela4 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela4 .= '</tr>';

$tabela4 .='</thead>'; 

$tabela4 .='<tbody>';

$tabela5 .= '<div style="float: center" table align="center">';

$tabela5 .= '<table border="5">';

$tabela5 .= '<tr>';

$tabela5 .='<thead>';

$tabela5 .= '<tr>';

$tabela5 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela5 .= '<th style="width:40px; text-align: center"><strong>Jantar</strong></th>';

$tabela5 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela5 .= '</tr>';

$tabela5 .='</thead>'; 

$tabela5 .='<tbody>';

$tabela6 .= '<div style="float: center" table align="center">';

$tabela6 .= '<table border="5">';

$tabela6 .= '<tr>';

$tabela6 .='<thead>';

$tabela6 .= '<tr>';

$tabela6 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela6 .= '<th style="width:40px; text-align: center"><strong>Jantar Dieta</strong></th>';

$tabela6 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela6 .= '</tr>';

$tabela6 .='</thead>'; 

$tabela6 .='<tbody>';

$tabela7 .= '<div style="float: center" table align="center">';

$tabela7 .= '<table border="5">';

$tabela7 .= '<tr>';

$tabela7 .='<thead>';

$tabela7 .= '<tr>';

$tabela7 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela7 .= '<th style="width:40px; text-align: center"><strong>Pequeno Almoço</strong></th>';

$tabela7 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela7 .= '</tr>';

$tabela7 .='</thead>'; 

$tabela7 .='<tbody>';

$tabela8 .= '<div style="float: center" table align="center">';

$tabela8 .= '<table border="5">';

$tabela8 .= '<tr>';

$tabela8 .='<thead>';

$tabela8 .= '<tr>';

$tabela8 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela8 .= '<th style="width:40px; text-align: center"><strong>Almoço</strong></th>';

$tabela8 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela8 .= '</tr>';

$tabela8 .='</thead>'; 

$tabela8 .='<tbody>';

$tabela9 .= '<div style="float: center" table align="center">';

$tabela9 .= '<table border="5">';

$tabela9 .= '<tr>';

$tabela9 .='<thead>';

$tabela9 .= '<tr>';

$tabela9 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela9 .= '<th style="width:40px; text-align: center"><strong>Almoço Dieta</strong></th>';

$tabela9 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';   

$tabela9 .= '</tr>';

$tabela9 .='</thead>'; 

$tabela9 .='<tbody>';

$tabela10 .= '<div style="float: center" table align="center">';

$tabela10 .= '<table border="5">';

$tabela10 .= '<tr>';

$tabela10 .='<thead>';

$tabela10 .= '<tr>';

$tabela10 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela10 .= '<th style="width:40px; text-align: center"><strong>Lanche</strong></th>';

$tabela10 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';  

$tabela10 .= '</tr>';

$tabela10 .='</thead>'; 

$tabela10 .='<tbody>';

$tabela11 .= '<div style="float: center" table align="center">';

$tabela11 .= '<table border="5">';

$tabela11 .= '<tr>';

$tabela11 .='<thead>';

$tabela11 .= '<tr>';

$tabela11 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela11 .= '<th style="width:40px; text-align: center"><strong>Jantar</strong></th>';

$tabela11 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';  

$tabela11 .= '</tr>';

$tabela11 .='</thead>'; 

$tabela11 .='<tbody>';

$tabela12 .= '<div style="float: center" table align="center">';

$tabela12 .= '<table border="5">';

$tabela12 .= '<tr>';

$tabela12 .='<thead>';

$tabela12 .= '<tr>';

$tabela12 .= '<th style="width:40px; text-align: center"><strong>Data</strong></th>';

$tabela12 .= '<th style="width:40px; text-align: center"><strong>Jantar Dieta</strong></th>';

$tabela12 .= '<th style="width:20px; text-align: center"><strong>Total</strong></th>';  

$tabela12 .= '</tr>';

$tabela12 .='</thead>'; 

$tabela12 .='<tbody>';

while($rows_cursos = mysqli_fetch_array($result)) {

$tabela1 .= '<tr>';  

$tabela1 .= '<td>'.$rows_cursos['data'].'</td>';

$tabela1 .= '<td>'.$rows_cursos['Pequeno Almoço'].'</td>';

$tabela1 .= '<td>'.$rows_cursos['Quantidade Peq. Alm.'].'</td>';

$tabela1 .= '</tr>'; 

$tabela2 .= '<tr>';  

$tabela2 .= '<td>'.$rows_cursos['data'].'</td>';

$tabela2 .= '<td>'.$rows_cursos['Almoço'].'</td>';

$tabela2 .= '<td>'.$rows_cursos['Quantidade Almoço'].'</td>';

$tabela2 .= '</tr>'; 

$tabela3 .= '<tr>';  

$tabela3 .= '<td>'.$rows_cursos['data'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Almoço Dieta'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Quantidade Alm. Die.'].'</td>';

$tabela3 .= '</tr>'; 

$tabela4 .= '<tr>';  

$tabela4 .= '<td>'.$rows_cursos['data'].'</td>';

$tabela4 .= '<td>'.$rows_cursos['Lanche'].'</td>';

$tabela4 .= '<td>'.$rows_cursos['Quantidade Lanche'].'</td>';

$tabela4 .= '</tr>'; 

$tabela5 .= '<tr>';  

$tabela5 .= '<td>'.$rows_cursos['data'].'</td>';

$tabela5 .= '<td>'.$rows_cursos['Jantar'].'</td>';

$tabela5 .= '<td>'.$rows_cursos['Quantidade Jantar'].'</td>';

$tabela5 .= '</tr>'; 

$tabela6 .= '<tr>';  

$tabela6 .= '<td>'.$rows_cursos['data'].'</td>';

$tabela6 .= '<td>'.$rows_cursos['Jantar Dieta'].'</td>';

$tabela6 .= '<td>'.$rows_cursos['Quantidade Jan. Die.'].'</td>';

$tabela6 .= '</tr>'; 

while($rows_cursos1 = mysqli_fetch_array($result1)) {

$tabela7 .= '<tr>';  

$tabela7 .= '<td>'.$rows_cursos1['data'].'</td>';

$tabela7 .= '<td>'.$rows_cursos1['Pequeno Almoço'].'</td>';

$tabela7 .= '<td>'.$rows_cursos1['Quantidade Peq. Alm.'].'</td>';

$tabela7 .= '</tr>'; 

$tabela8 .= '<tr>';  

$tabela8 .= '<td>'.$rows_cursos1['data'].'</td>';

$tabela8 .= '<td>'.$rows_cursos1['Almoço'].'</td>';

$tabela8 .= '<td>'.$rows_cursos1['Quantidade Almoço'].'</td>';

$tabela8 .= '</tr>'; 

$tabela9 .= '<tr>';  

$tabela9 .= '<td>'.$rows_cursos1['data'].'</td>';

$tabela9 .= '<td>'.$rows_cursos1['Almoço Dieta'].'</td>';

$tabela9 .= '<td>'.$rows_cursos1['Quantidade Alm. Die.'].'</td>';

$tabela9 .= '</tr>'; 

$tabela10 .= '<tr>';  

$tabela10 .= '<td>'.$rows_cursos1['data'].'</td>';

$tabela10 .= '<td>'.$rows_cursos1['Lanche'].'</td>';

$tabela10 .= '<td>'.$rows_cursos1['Quantidade Lanche'].'</td>';

$tabela10 .= '</tr>'; 

$tabela11 .= '<tr>';  

$tabela11 .= '<td>'.$rows_cursos1['data'].'</td>';

$tabela11 .= '<td>'.$rows_cursos1['Jantar'].'</td>';

$tabela11 .= '<td>'.$rows_cursos1['Quantidade Jantar'].'</td>';

$tabela11 .= '</tr>'; 

$tabela12 .= '<tr>';  

$tabela12 .= '<td>'.$rows_cursos1['data'].'</td>';

$tabela12 .= '<td>'.$rows_cursos1['Jantar Dieta'].'</td>';

$tabela12 .= '<td>'.$rows_cursos1['Quantidade Jan. Die.'].'</td>';

$tabela12 .= '</tr>'; 

}

}
$tabela1 .= '</tr>';

$tabela1 .='</tbody>'; 

$tabela1 .= '</table>';

$tabela1 .= '</div>';

echo $tabela1;

$tabela2 .= '</tr>';

$tabela2 .='</tbody>'; 

$tabela2 .= '</table>';

$tabela2 .= '</div>';

echo $tabela2;

$tabela3 .= '</tr>';

$tabela3 .='</tbody>'; 

$tabela3 .= '</table>';

$tabela3 .= '</div>';

echo $tabela3;

$tabela4 .= '</tr>';

$tabela4 .='</tbody>'; 

$tabela4 .= '</table>';

$tabela4 .= '</div>';

echo $tabela4;

$tabela5 .= '</tr>';

$tabela5 .='</tbody>'; 

$tabela5 .= '</table>';

$tabela5 .= '</div>';

echo $tabela5;

$tabela6 .= '</tr>';

$tabela6 .='</tbody>'; 

$tabela6 .= '</table>';

$tabela6 .= '</div>';

echo $tabela6;

$tabela7 .= '</tr>';

$tabela7 .='</tbody>'; 

$tabela7 .= '</table>';

$tabela7 .= '</div>';

echo $tabela7;

$tabela8 .= '</tr>';

$tabela8 .='</tbody>'; 

$tabela8 .= '</table>';

$tabela8 .= '</div>';

echo $tabela8;

$tabela9 .= '</tr>';

$tabela9 .='</tbody>'; 

$tabela9 .= '</table>';

$tabela9 .= '</div>';

echo $tabela9;

$tabela10 .= '</tr>';

$tabela10 .='</tbody>'; 

$tabela10 .= '</table>';

$tabela10 .= '</div>';

echo $tabela10;

$tabela11 .= '</tr>';

$tabela11 .='</tbody>'; 

$tabela11 .= '</table>';

$tabela11 .= '</div>';

echo $tabela11;

$tabela12 .= '</tr>';

$tabela12 .='</tbody>'; 

$tabela12 .= '</table>';

$tabela12 .= '</div>';

echo $tabela12;

I wanted $table 7 to $table 12 to be next to $table 1 to $table 6.

HTML:

$calendar .= "<td bgcolor='#F5F5F5' align='center' data-semana=''><center><font size='2px'/> 
<input type='checkbox' name='arrachar[$year, $month, $day][dia]' value='$year-$month-$day' $marcado_data $disabled> $year-$month-$day <br /> 
<input type='checkbox' name='arrachar[$year, $month, $day][OpcaoA]' value='Peq_Almoço' $marcado_pequeno $disabled> Peq. Almoço <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd]' value='$marcado_pequeno_qtd' style='width:65px; height: 22px' /> <br /> 
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoB]' value='Almoço' $marcado_almoco $disabled> Almoço <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd1]' value='$marcado_almoco_qtd' style='width:65px; height: 22px' /> <br /> 
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoC]' value='Almoço_(Dieta)' $marcado_dieta $disabled> Almoço (Dieta) <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd2]' value='$marcado_dieta_qtd' style='width:65px; height: 22px' /> <br /> 
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoD]' value='Lanche' $marcado_lanche $disabled> Lanche <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd3]' value='$marcado_lanche_qtd' style='width:65px; height: 22px' /><br /> 
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoE]' value='Jantar' $marcado_jantar $disabled> Jantar <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd4]' value='$marcado_jantar_qtd' style='width:65px; height: 22px' /> <br /> 
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoF]' value='Jantar_(Dieta)' $marcado_jantardie $disabled> Jantar (Dieta) <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd5]' value='$marcado_jantardie_qtd' style='width:65px; height: 22px' /> </font></center></td>";

}
  • can post the html generated to make it easier to understand?

  • html is inside a calendar and calendar data is inserted all in a column, now to extract the results using the SUBSTRING_INDEX mysql. In this case it will not help. I can put the queries if help

  • from what I understand, in the html generated, you want tables 7 to 12 to be next to tables 1 to 6 is that? So if you put one in question the code html how it is being generated is easier to know where to change

  • I put in question the html you requested.

  • Make a table with a row and two columns. In the first column put from 1 to 6 and in the other from 7 to 12

1 answer

1


Make one more table with two columns and put to print the tables 1 a 6 in the first column and 7 a 12 in the second column.

echo '<div><table border="1" width="100%"><tr><td>';

echo $tabela1;

echo $tabela2;

echo $tabela3;

echo $tabela4;

echo $tabela5;

echo $tabela6;

//segunda coluna

echo "</td><td>";

echo $tabela7;

echo $tabela8;

echo $tabela9;

echo $tabela10;

echo $tabela11;

echo $tabela12;

echo '</td></tr></table></div>';

Without applying style to this new table and without changing the css the existing Divs is something like this:

inserir a descrição da imagem aqui

Dai has to work with CSS to stay the way he wants.

  • This is exactly what I want, it worked well. How can I put a title to the tables from 1 to 6 and another title to the table from 7 to 12?

  • 1

    Put one more line <tr> in the new table echo '<div><table border="1" width="100%"> <tr><td style="text-align: center">TITULO ESQUERDA</td><td style="text-align: center">TITULO DIREITA</td> <tr><td>';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.