Jump to content

Recommended Posts

OK I have an array

The array contain task table names and their subtask table names.

I have a foreach loop which should go through the array and give me back the query result from a page that I include inside the loop.

 

here is the page codes

 

details.php

<?php
require('config.php');
include('includes/mysql.php');
$tasks = array("sales" => "salessub", "cdrawings" => "cdsub", "newequiptment" => "neweqsub", "subitems" => "subitemsub", "manufeng" => "mesub", "misc" => "miscsub", "quotebom" => "qbsub", "recbomitems" => "recbisub", "production" => "prodsub", "shipment" => "shipsub", "costaccount" => "casub", "prodreview" => "prodrevsub");
$tasknames = array("Sales" => "sales", "Customer Drawing Review" => "cdrawings", "New Equiptment" => "newequiptment", "Submission Items" => "subitems", "Manufacturing & Engineering" => "manufeng", "Miscellaneous" => "misc", "Quote & Order BOM Items" => "quotebom", "Receive BOM Items" => "recbomitems", "Production" => "production", "Shipment" => "shipment", "Cost Accounting" => "costaccount", "Product Review" => "prodreview");
$pid = $_GET['pid'];
$sql = "SELECT * FROM partnumbers WHERE PartID = '$pid'";
$res = mysql_query($sql) or die (mysql_error());
$r = mysql_fetch_assoc($res);
?>
<table width=400 align=center>
<tr>
   <td colspan=3 align=center><b>Details for part #<? echo $r['PartNumber']; ?><br /> </b></td>
</tr>
<tr>
   <td align=center>Customer<br /><? echo $r['Customer']; ?></td>
   <td align=center>Item Number<br /><? echo $r['ItemNumber']; ?></td>
   <td align=center>PJ Number<br /><? echo $r['PJNum']; ?></td>
</tr>
<tr>
   <td colspan=3> </td>
</tr>
<tr>
   <td align=center>PPAP Date<br /><? echo date("m/d/Y", strtotime($r['PPAPDate'])); ?></td>
   <td align=center>Due Date<br /><? echo date("m/d/Y", strtotime($r['OrderDate'])); ?></td>
   <td align=center>% Complete<br /><? echo ($r['PercentComp']*100)."%"; ?></td>
</tr>
</table>
<?php
foreach($tasks as $ttable => $stable){
include('tasks.php');
}
?>

 

And here is tasks.php

<?php
$tasksql = "SELECT ".$ttable.".".$ttable."ID AS taskid, $ttable.SchDate AS schdate, $ttable.ActDate AS actdate, $ttable.PercComp AS tpercent,
            ".$stable.".".$stable."ID AS subid, $stable.Description AS des, $stable.Res AS res, $stable.Status AS status, $stable.StDate AS startdate, $stable.CompDate AS compdate
            FROM $ttable LEFT JOIN $stable ON ".$ttable.".".$ttable."ID = ".$stable.".".$ttable."ID
            WHERE $ttable.PartID = '$pid'
            ORDER BY ".$ttable.".".$ttable."ID ASC";
// echo "$tasksql<br />";
$tres = mysql_query($tasksql) or die (mysql_error());
$bgcolor = "FFFFFF";
$lasttask = '';
while($tr = mysql_fetch_assoc($tres)){
  // Print Group Name
  if ($tr['taskid'] != $lasttask) {
  echo "<table width=550 align=center>
          <tr bgcolor=yellow>
            <td width=200>".array_search($ttable, $tasknames)."</td>
            <td width=125>".date("m/d/Y", strtotime($tr['schdate']))."</td>
            <td width=125>".date("m/d/Y", strtotime($tr['actdate']))."</td>
            <td width=100>".($tr['tpercent']*100)."%</td>
          </tr>
        </table>\n";
  }
// Alternate row color
if ($bgcolor == "#E0E0E0"){
  $bgcolor = "#FFFFFF";
} else {
  $bgcolor = "#E0E0E0";
}
// Print Database Details
echo "<table width=550 align=center>
        <tr>
          <td>".$tr['subid']."</td>
        </tr>
      </table>\n";
// Reset group values
$lasttask = $tr['taskid'];
}
mysql_free_result($tres);
?>

 

when I do this I just get the first or last result nothing else

 

it I take out include('tasks.php'); and just put in $ttable it goes fine.

 

Any ideas??

 

Ray

Link to comment
https://forums.phpfreaks.com/topic/36689-solved-loop-not-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.