Connecting Tech Pros Worldwide Forums | Help | Site Map

populate a dinamic table with two different querys.

Chifo
Guest
 
Posts: n/a
#1: May 11 '06
hello.
i have a problem with a populate html table with data from table here
it's the problem

two querys retrieving data from table, one of querys show me a
colletion of data from 6:00 am to 15:30 pm timestampz, i put this on a
part of html table. when time on my if condition es great than 15:31,
showme data from 15:31 to 23:59 timestamp and populate another part of
html table.
but, data in html first part,it's gone away.
how can i put on html table data from two querys in same table?


Rik
Guest
 
Posts: n/a
#2: May 12 '06

re: populate a dinamic table with two different querys.


Chifo wrote:[color=blue]
> hello.
> i have a problem with a populate html table with data from table here
> it's the problem
>
> two querys retrieving data from table, one of querys show me a
> colletion of data from 6:00 am to 15:30 pm timestampz, i put this on a
> part of html table. when time on my if condition es great than 15:31,
> showme data from 15:31 to 23:59 timestamp and populate another part of
> html table.
> but, data in html first part,it's gone away.
> how can i put on html table data from two querys in same table?[/color]

By running the first query, fetch the data, display it, run the second
query, fetch the data, and display it? Just don't close the table an open
another in between....

Without code, it's difficult to see what you're doing wrong.
This should be absolutely no problem at all

Keep in mind that you might have to choose different names for variables
you're used to call a certain name, to prevent overwriting them. Also: you
don't really put something into a table, you just return your results
surrounded by echoing some markup, so it's not that much different then just
spitting out raw data.

Grtz,
--
Rik Wasmus


Toby Inkster
Guest
 
Posts: n/a
#3: May 12 '06

re: populate a dinamic table with two different querys.


Chifo wrote:
[color=blue]
> but, data in html first part,it's gone away.
> how can i put on html table data from two querys in same table?[/color]

<?php

$table1 = "<table>\n"
. "<caption>15:30 and earlier</caption>\n"
. "<tr><th>Time</th><th>Thingy</th></tr>\n";

$table2 = "<table>\n"
. "<caption>15:31 and later</caption>\n"
. "<tr><th>Time</th><th>Thingy</th></tr>\n";

$results = pg_query($db, "SELECT time,thingy FROM mydata ORDER BY thingy;");
while($row = pg_fetch_assoc($results))
{
$time = strtotime($row['time']);

$trow = sprintf("<tr><td>%s</td><td>%s</td></tr>\n"
,htmlentities(date('H:m', $time))
,htmlentities(substr($row['thingy'], 0, 200))
);

if (date('Hm', $time) > 1530)
$table1 .= $trow;
else
$table2 .= $trow;
}

$table1 .= "</table>\n";
$table2 .= "</table>\n";

print $table1."<hr>\n".$table2;

?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Chifo
Guest
 
Posts: n/a
#4: May 12 '06

re: populate a dinamic table with two different querys.


here is the code
<meta http-equiv="refresh" content="60">
<?php

$line=$_GET['Linea'];

include ("conexion.php");
$shift1BeginHour=date("Y-m-d")." "."12:00:00";
$shift1EndHour=date("Y-m-d")." "."21:29:00";
$shift2BeginHour=date("Y-m-d")." "."21:30:00";
$YearMonths=date("Y-m");
$day=date("d");
$nextDay=$day+1;
$shift2EndHour=$YearMonths."-".$nextDay." "."05:59:00";
/*date("Y-m-d")." "."05:59:00";*/
/*************************************************v ARIABLES PARA
SHIFT2******************************************** **********/
$percentYield2=0;
$totalYield2=0;
$newPartS=array();
$newQtyS=array();
$newFpyS=array();
$newPartS1=array();
$newQtyS1=array();
$newFpyS1=array();
$total2=0;
$newPart1s=array();
$newQty1s=array();
$newFpy1s=array();
$totalYs=array();
$totalYields=0;
/************************************************** ************************************************** ************************/

$meta=0;
$meta2=0;
/*$meta_x_hora= $meta / 8.5;*/
$total=0;
$shift1Total=0;
$shift1TotalReal=0;
$percent=0;
$rate=0;
$expected_rate=0;
$totalFpy=0;
$j=0;
$percentYield=0;
$totalYield=0;
$newPart=array();
$newQty=array();
$newFpy=array(10);
$newPart1=array(10);
$newQty1=array(10);
$newFpy1=array(10);
$totalY=array(10);
$ProdDaysS1=array(10);
$ProdDaysS2=array(10);
$i=0;
$result=pg_query("SELECT part_no, COUNT(part_no) as partes,
COUNT(fts_count) as fpy FROM table WHERE prod_day =extract(doy from
current_date) AND id_prefix = 'CAX' AND cell_nb =$line and fts_count=1
GROUP BY part_no ORDER BY partes ") or die ("No se ejecuto el query" .
pg_last_error());

/* $result1=pg_query("select part_no, COUNT(part_no) as partes,
COUNT(fts_count) as fpy from vw_wip_fpy_top where prod_day =
extract(doy from current_date) and id_prefix = 'CAX' and ship_time
between '$shift1BeginHour'::timestamptz and
'$shift1EndHour'::timestamptz
and cell_nb =$line GROUP BY part_no order by
part_no") or die ("No se ejecuto el query" . pg_last_error());
while($rows1=pg_fetch_array($result1)){
$newPart[]=$rows1[0];
$newQty[]=$rows1[1];
$newFpy[]=$rows1[2];
$total+=$rows1[1];
;/*Produccion Actual sacado del query*/

include ("shift1and2.php");






$horaActual=Date("H:i");
while($rows=pg_fetch_array($result)){
$newPart1[]=$rows['part_no'];
$newQty1[]=$rows['partes'];
$newFpy1[]=$rows['fpy'];
$totalYield+=$rows['fpy'];
$totalY[]=$rows['partes'];
}
/**********************************Codigo agregado
17/04/7006*************************************/
$FirstP=$totalYield;
?><title>Production Information</title>


<style type="text/css">
<!--
..style1 {
color: #0089C0;
font-weight: bold;
font-size: large;
}
..style9 {font-size: large; font-weight: bold; }
..style10 {font-family: Arial, Helvetica, sans-serif}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
..style12 {color: #FFFFFF; font-weight: bold; font-size: large; }
..style13 {font-size: large}
..style14 {
font-family: Arial, Helvetica, sans-serif;
font-size: large;
font-weight: bold;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"><table width="1221" height="461" border="2"
align="center" cellspacing="0" bordercolor="#000000">
<tr>
<td width="1213" valign="top"><div id="Layer3"
style="position:absolute; width:861px; height:71px; z-index:3; left:
68px; top: 76px;">
<table width="825" height="70" border="1" align="center"
cellspacing="0" bordercolor="#000000">
<tr>
<td width="598" height="31">
<?
if($horaActual>="06:00" and $horaActual<$shift1[8]){
$result1=pg_query("select part_no, COUNT(part_no) as
partes, COUNT(fts_count) as fpy from table where prod_day =
extract(doy from current_date) and id_prefix = 'CAX' and ship_time
between '$shift1BeginHour'::timestamptz and
'$shift1EndHour'::timestamptz
and cell_nb =$line GROUP BY part_no order by
part_no") or die ("No se ejecuto el query" . pg_last_error());

while($rows1=pg_fetch_array($result1)){
$newPart[]=$rows1['part_no'];
$newQty[]=$rows1['partes'];
$newFpy[]=$rows1['fpy'];
$total+=$rows1['partes'];

}

$s1=$total;
if ($line=1 or $line=2 or $line=5 or $line=12){

$meta=450;
$meta2=400;
for ($i=1;$i<=8;$i++){
$ProdDays1[$i]=$meta/7.5;
}
for ($i=1;$i<=7;$i++){
$ProdDaysS2[$i]=$meta2/6.5;
}
}
if ($line=3 or $line=13){

$meta=650;
$meta2=575;
for ($i=1;$i<=8;$i++){
$ProdDays1[$i]=$meta/7.5;
}
for ($i=1;$i<=7;$i++){
$ProdDaysS2[$i]=$meta2/6.5;
}
}
if ($line=7 or $line=8 or $line=9 or $line=10 or $line=11 or $line=14
or $line=15 or $line=17){

$meta=774;
$meta2=683;
for ($i=1;$i<=8;$i++){
$ProdDays1[$i]=$meta/7.5;
}
for ($i=1;$i<=7;$i++){
$ProdDaysS2[$i]=$meta2/6.5;
}
}
$rate=($total/$meta)*100;
$expected_rate=$rate*7.5;
if ($horaActual>$shift1[0] && $horaActual<$shift1[1]) {/*7:00 am
produccion=53;*/

if ($total <= $expected_rate){
echo "<img src=rojo.gif width=$total height=70>";

}
else
{
echo "<img src=verde.gif width=$total height=70>";

}
}
if ($horaActual>$shift1[1] && $horaActual<$shift1[2]) {/*8:00
am produccion=106;*/
if ( $total<= $expected_rate){
echo "<img src=rojo.gif width=$total height=70>";
;
}
else
{
echo "<img src=verde.gif width=$total height=70>";

}
}
if ($horaActual>$shift1[2] && $horaActual<$shift1[3])
{/*9:00 am produccion =159*/
if ($total <= $expected_rate){
echo "<img src=rojo.gif width=$total
height=70>";
}
else
{
echo "<img src=verde.gif width=$total
height=70>";
}
}
if ($horaActual>$shift1[3] &&
$horaActual<$shift1[4]) {/*10:00 am produccion=212;*/

if ($total <=$expected_rate ){
echo "<img src=rojo.gif
width=$total height=70>";

}
else
{
echo "<img src=verde.gif
width=$total height=70>";

}
}
if ($horaActual>$shift1[4]
&& $horaActual<$shift1[5]) {/*11:00 am produccion=265;*/
if ($total
<=$expected_rate){
echo "<img
src=rojo.gif width=$total height=70>";

}
else
{
echo "<img
src=verde.gif width=$total height=70>";

}
}


if ($horaActual>$shift1[5] &&
$horaActual<$shift1[6]) {/*12:00 produccion=318;*/

if ($total <= $expected_rate){
echo
"<img src=rojo.gif width=$total height=70>";

}
else
{
echo
"<img src=verde.gif width=$total height=70>";
$ProdDays1[5];
}
}
if ($horaActual>$shift1[6]
&& $horaActual<$shift1[7]) {/*13:00 produccion=370;*/

if ($total <= $expected_rate){

echo
"<img src=rojo.gif width=$total height=70>";

}
else
{
echo
"<img src=verde.gif width=$total height=70>";

}
}
if ($horaActual>$shift1[7] &&
$horaActual<$shift1[8]) {/*14:00 produccion=423;*/

if ($total <= $expected_rate){

echo
"<img src=rojo.gif width=$total height=70>";

}
else
{

echo
"<img src=verde.gif width=$total height=70>";

}
}
if ($horaActual>$shift1[8] &&
$horaActual<$shift2[0]) {/*15.30:00 produccion=470;*/
if
($total <=$expected_rate ){
echo
"<img src=rojo.gif width=$total height=70>";

}
else
{
echo
"<img src=verde.gif width=$total height=70>";

}
}

}

/*pg_free_result($result1);
pg_free_result($result);*/

if($horaActual>="15:30" and $horaActual<$shift2[7]){
include ("conexion.php");
$totalshift2=pg_query("select part_no, COUNT(part_no) as partes,
COUNT(fts_count) as fpy from table where prod_day = extract(doy from
current_date) and id_prefix = 'CAX' and ship_time between
'$shift2BeginHour'::timestamptz and '$shift2EndHour'::timestamptz
and cell_nb = $line GROUP BY part_no ORDER BY part_no") or die ("No se
ejecuto el query" . pg_last_error());
$resultShift2=pg_query("SELECT part_no, COUNT(part_no) as partes,
COUNT(fts_count) as fpy FROM table WHERE prod_day =extract(doy from
current_date) AND id_prefix = 'CAX' and ship_time between
'$shift2BeginHour'::timestamptz and '$shift2EndHour'::timestamptz AND
cell_nb =$line and fts_count=1 GROUP BY part_no ORDER BY part_no") or
die ("No se ejecuto el query" . pg_last_error());
while($rowshift2=pg_fetch_array($resultShift2)){
$newPart1s[]=$rowshift2[0];
$newQty1s[]=$rowshift2[1];
$newFpy1s[]=$rowshift2[2];
$totalYields+=$rowshift2[2];
$totalYs[]=$rowshift2[2];
}
while($rows2=pg_fetch_array($totalshift2)){
$newPartS[]=$rows2[0];
$newQtyS[]=$rows2[1];
$newFpyS[]=$rows2[2];
$total2+=$rows2[1];

}

/************************************************** ************************************************** ******************/
if ($line=1 or $line=2 or $line=5 or $line=12){


$meta2=400;

for ($i=1;$i<=7;$i++){
$ProdDays2[$i]=$meta2/6.5;
}
}
if ($line=3 or $line=13){


$meta2=575;

for ($i=1;$i<=7;$i++){
$ProdDays2[$i]=$meta2/7.5;
}
}
if ($line=7 or $line=8 or $line=9 or $line=10 or $line=11 or $line=14
or $line=15 or $line=17){


$meta2=683;

for ($i=1;$i<=7;$i++){
$ProdDays2[$i]=$meta2/7.5;
}
}

/************************************************** ************************************************** ******************/
$rate=($total2/$meta2)*100;
$expected_rate=$rate*7.5;
if ($horaActual>$shift1[0] && $horaActual<$shift2[1]) {/*16:30
produccion=53;*/
echo $shift2[1];
if ($total2 <= $expected_rate){
echo "<img src=rojo.gif width=$total2 height=70>";
}
else
{
echo "<img src=verde.gif width=$total2 height=70>";
}
}
if ($horaActual>$shift2[1] && $horaActual<$shift2[2]) {/*17:30
produccion=106;*/
if ( $total2<= $expected_rate){
echo "<img src=rojo.gif width=$total2 height=70>";

}
else
{
echo "<img src=verde.gif width=$total2 height=70>";
}
}
if ($horaActual>$shift2[2] && $horaActual<$shift2[3])
{/*18:30 produccion =159*/

if ($total2 <= $expected_rate){
echo "<img src=rojo.gif width=$total2 height=70>";
echo $horaActual;
}
else
{
echo "<img src=verde.gif width=$total2 height=70>";
}
}
if ($horaActual>$shift2[3] && $horaActual<$shift2[4])
{/*19:30 produccion=212;*/
if ($total2 <=$expected_rate ){
echo "<img src=rojo.gif width=$total2
height=70>";
}
else
{
echo "<img src=verde.gif width=$total2
height=70>";

}
}
if ($horaActual>$shift2[4] &&
$horaActual<$shift2[5]) {/*20:30 produccion=265;*/
if ($total2 <=$expected_rate ){
echo "<img src=rojo.gif width=$total2
height=70>";
}
else
{
echo "<img src=verde.gif width=$total2
height=70>";
}
}
if ($horaActual>$shift2[5] && $horaActual<$shift2[6])
{/*21:30 produccion=318;*/
if ($total2 <= $expected_rate){
echo "<img src=rojo.gif width=$total2
height=70>";
}
else
{
echo "<img src=verde.gif
width=$total2 height=70>";
}
}
if ($horaActual>$shift2[6] && $horaActual<$shift2[7])
{/*22:30 produccion=370;*/
if ($total2 <= $expected_rate){
echo "<img src=rojo.gif
width=$total2 height=70>";
}
else
{
echo "<img src=verde.gif
width=$total2 height=70>";

}
}
if ($horaActual>$shift2[7] && $horaActual<$shift1[0])
{/*23:30 produccion=423;*/
if ($total2 <= $expected_rate){
echo "<img src=rojo.gif
width=$total2 height=70>";
}
else
{
echo "<img
src=verde.gif width=$total2 height=70>";

}
}
}
?>
</td>

</tr>
</table>
</div>

<p><?=$horaActual;?></p>
<div id="Layer2" style="position:absolute; width:242px; height:70px;
z-index:2; left: 952px; top: 118px;">


<table width="243" bordercolor="#000000">
<tr bgcolor="#f87870">

<td width="73" bgcolor="#173a60"><span
class="style12">Rate</span></td>
<td width="270" bgcolor="#173a60"><span class="style12">Expected
Rate </span></td>
</tr>
<tr >
<? if($horaActual>="06:00" and $horaActual<"15:30"){?>
<? $percentYield=($totalYield/$total)*100?>

<td><div align="center"><span class="style14"><? echo
number_format($rate,2); ?></span></div></td>
<td><div align="center"><span class="style14"><? echo
number_format($expected_rate,2);?></span></div></td>
</tr>
<? }?>
<!-- /*******************rate segundo
turno******************************************/ -->
<? if($horaActual>="15:30" and $horaActual<"23:59"){?>


<td><div align="center"><span class="style14"><? echo
number_format($rate,2); ?></span></div></td>
<td><div align="center"><span class="style14"><? echo
number_format($expected_rate,2);?></span></div></td>
</tr>
<? }?>
</table>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><br>
<br>
<br>
</p>
<table width="820" height="92" bordercolor="#000000">
<tr >
<td width="34" rowspan="6">&nbsp;</td>
<td width="195" height="28" bgcolor="#173a60"><span
class="style12">Produced Model </span></td>
<td width="51" bgcolor="#173a60"><span
class="style12">Qty</span></td>
<td width="80" bgcolor="#173a60"><span
class="style12">FPY%</span></td>
<td width="122" bgcolor="#173a60"><span class="style12">FPY
S1</span></td>
<td width="168" bgcolor="#173a60"><span
class="style12">Shift2</span></td>
<td width="138" bgcolor="#173a60"><span class="style12">FPY
S2</span></td>

</tr>
<tr >
<? if($horaActual>="06:00" and $horaActual<$shift1[8]){?>
<? for ($j=0;$j<pg_num_rows($result1);$j++){?>

<td height="20" > <div align="left" class="style10
style13"><strong><? echo $newPart[$j];?> </strong></div></td>
<? $percent=($totalY[$j]/$newQty[$j])*100;?>

<td><div align="center" class="style14"><? echo
$newQty[$j];?></div></td>
<td><div align="center" class="style14"><? echo
number_format($percent,2); ?></div></td>
<? /*$Quant=$percent;*/?>
<td><div align="center" class="style14"><? echo
$newFpy1[$j];?></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>

</tr> <? } ?> <? }?>
<!-- /*******************Produccion segundo
turno******************************************/ -->
<? if($horaActual>="15:30" and $horaActual<$shift2[7]){?>

<? for ($j=0;$j<pg_num_rows($totalshift2);$j++){?>
<tr>
<td height="31" > <div align="left" class="style10
style13"><strong><? echo $newPartS[$j];?> </strong></div></td>
<? $percentYield2=($totalYields[$j]/$newQtyS[$j])*100;?>
<td><div align="center" class="style14"><?=$s1;?></div></td>
<td><div align="center" class="style14"></div></td>


<td><div align="center" class="style14">
<?=$FirstP;?>
</div></td>
<td><div align="center"><span class="style14"><? echo
$newQtyS[$j];?></span></div></td>
<td><div align="center"><span class="style14"><? echo
$newFpy1s[$j]?></span></div></td>

</tr> <? } ?> <? }?>
</table>

<br>
<div id="Layer1" style="position:absolute; width:247px; height:51px;
z-index:1; left: 949px; top: 230px;">
<table width="246" bordercolor="#000000">
<tr >
<td width="109" bgcolor="#173a60"><div align="center"><span
class="style12">Produced</span></div></td>
<td width="85" bgcolor="#173a60"><div align="center"><span
class="style12">Yield</span></div></td>
</tr>
<tr ><? if($horaActual>="06:00" and $horaActual<"15:30"){?>
<td><div align="center"><span class="style14">
<?=number_format($total,2); ?>
</span></div></td>
<td><div align="center"><span class="style14">
<?=number_format($percentYield,2)." "."%"; ?>
</span></div></td>
</tr><br>
<? } ?>
<!-- /*******************Produce and Yield segundo
turno******************************************/ -->
<? if($horaActual>="15:30" and $horaActual<"23:59"){?>
<td><div align="center"><span class="style14">
<?=number_format($total2,2); ?>
</span></div></td>
<td><div align="center"><span class="style14">
<? if ($totalyields=0 and $total=0) {
$totalYield2=0;
}
else
{
$totalYield2=($totalYields/$total2)*100;
echo number_format($totalYield2,2)." "."%";
}?>
</span></div></td>
</tr><br><? }?>
</table>
<span class="style14"> </span></div>
<table width="821" height="27" bordercolor="#000000">
<tr>
<td width="169"><span class="style1">Total</span></td>
<td width="46"><div align="center"><span class="style9">
<?=number_format($total,0); ?>
</span></div></td>
<td width="113"><div align="center"></div></td>
<td width="121"><div align="center"></div></td>
<!-- /*******************Total segundo
turno******************************************/ -->
<? if($horaActual>="15:30" and $horaActual<$shift2[7]){?>

<td width="179"> <div align="center"><span
class="style9"><?=$total2; ?>
</span></div></td><? }?>
<td width="128"><div align="center"></div></td>
</tr>
</table>


</td>
</tr>
</table>

Closed Thread