populate a dinamic table with two different querys.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chifo

    populate a dinamic table with two different querys.

    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

    #2
    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


    Comment

    • Toby Inkster

      #3
      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>1 5:30 and earlier</caption>\n"
      . "<tr><th>Ti me</th><th>Thingy</th></tr>\n";

      $table2 = "<table>\n"
      . "<caption>1 5:31 and later</caption>\n"
      . "<tr><th>Ti me</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><t d>%s</td><td>%s</td></tr>\n"
      ,htmlentities(d ate('H:m', $time))
      ,htmlentities(s ubstr($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

      Comment

      • Chifo

        #4
        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" );
        $shift1BeginHou r=date("Y-m-d")." "."12:00:00 ";
        $shift1EndHour= date("Y-m-d")." "."21:29:00 ";
        $shift2BeginHou r=date("Y-m-d")." "."21:30:00 ";
        $YearMonths=dat e("Y-m");
        $day=date("d");
        $nextDay=$day+1 ;
        $shift2EndHour= $YearMonths."-".$nextDay. " "."05:59:00 ";
        /*date("Y-m-d")." "."05:59:00 ";*/
        /*************** *************** *************** ****vARIABLES PARA
        SHIFT2********* *************** *************** ***************/
        $percentYield2= 0;
        $totalYield2=0;
        $newPartS=array ();
        $newQtyS=array( );
        $newFpyS=array( );
        $newPartS1=arra y();
        $newQtyS1=array ();
        $newFpyS1=array ();
        $total2=0;
        $newPart1s=arra y();
        $newQty1s=array ();
        $newFpy1s=array ();
        $totalYs=array( );
        $totalYields=0;
        /*************** *************** *************** *************** *************** *************** *************** *************** ****/

        $meta=0;
        $meta2=0;
        /*$meta_x_hora= $meta / 8.5;*/
        $total=0;
        $shift1Total=0;
        $shift1TotalRea l=0;
        $percent=0;
        $rate=0;
        $expected_rate= 0;
        $totalFpy=0;
        $j=0;
        $percentYield=0 ;
        $totalYield=0;
        $newPart=array( );
        $newQty=array() ;
        $newFpy=array(1 0);
        $newPart1=array (10);
        $newQty1=array( 10);
        $newFpy1=array( 10);
        $totalY=array(1 0);
        $ProdDaysS1=arr ay(10);
        $ProdDaysS2=arr ay(10);
        $i=0;
        $result=pg_quer y("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_que ry("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 '$shift1BeginHo ur'::timestampt z 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($r esult1)){
        $newPart[]=$rows1[0];
        $newQty[]=$rows1[1];
        $newFpy[]=$rows1[2];
        $total+=$rows1[1];
        ;/*Produccion Actual sacado del query*/

        include ("shift1and2.ph p");






        $horaActual=Dat e("H:i");
        while($rows=pg_ fetch_array($re sult)){
        $newPart1[]=$rows['part_no'];
        $newQty1[]=$rows['partes'];
        $newFpy1[]=$rows['fpy'];
        $totalYield+=$r ows['fpy'];
        $totalY[]=$rows['partes'];
        }
        /*************** *************** ****Codigo agregado
        17/04/7006*********** *************** ***********/
        $FirstP=$totalY ield;
        ?><title>Produc tion 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="#0 00000">
        <tr>
        <td width="1213" valign="top"><d iv 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="#0 00000">
        <tr>
        <td width="598" height="31">
        <?
        if($horaActual> ="06:00" and $horaActual<$sh ift1[8]){
        $result1=pg_que ry("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 '$shift1BeginHo ur'::timestampt z 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($r esult1)){
        $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>$s hift1[0] && $horaActual<$sh ift1[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>$s hift1[1] && $horaActual<$sh ift1[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>$s hift1[2] && $horaActual<$sh ift1[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>$s hift1[3] &&
        $horaActual<$sh ift1[4]) {/*10:00 am produccion=212; */

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

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

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

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

        }
        }


        if ($horaActual>$s hift1[5] &&
        $horaActual<$sh ift1[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>$s hift1[6]
        && $horaActual<$sh ift1[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>$s hift1[7] &&
        $horaActual<$sh ift1[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>$s hift1[8] &&
        $horaActual<$sh ift2[0]) {/*15.30:00 produccion=470; */
        if
        ($total <=$expected_rat e ){
        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<$sh ift2[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
        '$shift2BeginHo ur'::timestampt z 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=p g_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
        '$shift2BeginHo ur'::timestampt z 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($rowshift 2=pg_fetch_arra y($resultShift2 )){
        $newPart1s[]=$rowshift2[0];
        $newQty1s[]=$rowshift2[1];
        $newFpy1s[]=$rowshift2[2];
        $totalYields+=$ rowshift2[2];
        $totalYs[]=$rowshift2[2];
        }
        while($rows2=pg _fetch_array($t otalshift2)){
        $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>$s hift1[0] && $horaActual<$sh ift2[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>$s hift2[1] && $horaActual<$sh ift2[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>$s hift2[2] && $horaActual<$sh ift2[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>$s hift2[3] && $horaActual<$sh ift2[4])
        {/*19:30 produccion=212; */
        if ($total2 <=$expected_rat e ){
        echo "<img src=rojo.gif width=$total2
        height=70>";
        }
        else
        {
        echo "<img src=verde.gif width=$total2
        height=70>";

        }
        }
        if ($horaActual>$s hift2[4] &&
        $horaActual<$sh ift2[5]) {/*20:30 produccion=265; */
        if ($total2 <=$expected_rat e ){
        echo "<img src=rojo.gif width=$total2
        height=70>";
        }
        else
        {
        echo "<img src=verde.gif width=$total2
        height=70>";
        }
        }
        if ($horaActual>$s hift2[5] && $horaActual<$sh ift2[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>$s hift2[6] && $horaActual<$sh ift2[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>$s hift2[7] && $horaActual<$sh ift1[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><?=$horaActu al;?></p>
        <div id="Layer2" style="position :absolute; width:242px; height:70px;
        z-index:2; left: 952px; top: 118px;">


        <table width="243" bordercolor="#0 00000">
        <tr bgcolor="#f8787 0">

        <td width="73" bgcolor="#173a6 0"><span
        class="style12" >Rate</span></td>
        <td width="270" bgcolor="#173a6 0"><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="#0 00000">
        <tr >
        <td width="34" rowspan="6">&nb sp;</td>
        <td width="195" height="28" bgcolor="#173a6 0"><span
        class="style12" >Produced Model </span></td>
        <td width="51" bgcolor="#173a6 0"><span
        class="style12" >Qty</span></td>
        <td width="80" bgcolor="#173a6 0"><span
        class="style12" >FPY%</span></td>
        <td width="122" bgcolor="#173a6 0"><span class="style12" >FPY
        S1</span></td>
        <td width="168" bgcolor="#173a6 0"><span
        class="style12" >Shift2</span></td>
        <td width="138" bgcolor="#173a6 0"><span class="style12" >FPY
        S2</span></td>

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

        <td height="20" > <div align="left" class="style10
        style13"><stron g><? echo $newPart[$j];?> </strong></div></td>
        <? $percent=($tota lY[$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=$percen t;*/?>
        <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<$sh ift2[7]){?>

        <? for ($j=0;$j<pg_num _rows($totalshi ft2);$j++){?>
        <tr>
        <td height="31" > <div align="left" class="style10
        style13"><stron g><? 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="#0 00000">
        <tr >
        <td width="109" bgcolor="#173a6 0"><div align="center"> <span
        class="style12" >Produced</span></div></td>
        <td width="85" bgcolor="#173a6 0"><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_forma t($total,2); ?>
        </span></div></td>
        <td><div align="center"> <span class="style14" >
        <?=number_forma t($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_forma t($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="#0 00000">
        <tr>
        <td width="169"><sp an class="style1"> Total</span></td>
        <td width="46"><div align="center"> <span class="style9">
        <?=number_forma t($total,0); ?>
        </span></div></td>
        <td width="113"><di v align="center"> </div></td>
        <td width="121"><di v align="center"> </div></td>
        <!-- /*************** ****Total segundo
        turno********** *************** *************** **/ -->
        <? if($horaActual> ="15:30" and $horaActual<$sh ift2[7]){?>

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


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

        Comment

        Working...