I need to print several querys in different columns in an html table

1

I have a large table and for each column I need a different query, the problem is that I can not get the data printed in the column on the next right;

$connect = odbc_connect("proyecto", "usuario", "contrasena");
print ("Fecha de Inicio: $newDate1  Fecha Final: $newDate2");
# query the datos table giving group of vendedor and count of vendedor
$query = "SELECT  datos.vendedor, count (vendedor)                 
FROM datos where datos.fecha_reg >= #$newDate1# and datos.fecha_reg  <= 
#$newDate2#
 GROUP BY vendedor
 ORDER BY vendedor";

# perform the query
$result = odbc_exec($connect, $query);

# fetch the data from the database
while(odbc_fetch_row($result)){
$s1 = odbc_result($result, 1);
$s2 = odbc_result($result, 2);
print("<tr><th>$s1</th><th> $s2 </th></tr>");
}
# connect to a DSN "mydb" with a user and password 
$connect2 = odbc_connect("proyecto", "usuario", "contrasena");
$query2 = "SELECT  datos.modelo, count (modelo)                 
 FROM datos where datos.fecha_reg >= #$newDate1# and datos.fecha_reg  <= 
 #$newDate2#
 GROUP BY modelo
 ORDER BY modelo";
 # perform the query2
$result2 = odbc_exec($connect2, $query2);
# fetch the data from the database
while(odbc_fetch_row($result2)){
  $x1 = odbc_result($result2, 1);
  $x2 = odbc_result($result2, 2);
  print("<tr><th><th><th>$x1</th><th> $x2 </th></th></th></tr>");
}
# close the connection
odbc_close($connect);  
odbc_close($connect2);

This code is only 2 queries, I need to make several, but the result of the second query is printed below instead of next to the first two columns.

    
asked by Juan Pablo Navarro 16.06.2017 в 18:18
source

1 answer

1

The <tr> tag indicates that the content is a table row ( T able R ow in English). The results of both queries are written in their own rows ( <tr>...</tr> ) and that is why they are displayed on top of each other.

If you want the cells that you get in the second query to appear in the same row as the cells that you print in the first query, what you should do is put them all within the same <tr> . That is, do not make </tr> in the first print and also do <tr> in the second print .

Something like this (only the related code and I took advantage to remove th left over):

...

# fetch the data from the database
while(odbc_fetch_row($result)){
$s1 = odbc_result($result, 1);
$s2 = odbc_result($result, 2);
  print("<tr><th>$s1</th><th> $s2 </th>");
}

...

# fetch the data from the database
while(odbc_fetch_row($result2)){
  $x1 = odbc_result($result2, 1);
  $x2 = odbc_result($result2, 2);
  print("<th>$x1</th><th> $x2 </th></tr>");
}

...
    
answered by 16.06.2017 в 20:09