craygo Posted February 1, 2007 Share Posted February 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/36689-solved-loop-not-working/ Share on other sites More sharing options...
craygo Posted February 1, 2007 Author Share Posted February 1, 2007 It works fine!!!! There was a problem with the data. The tasks for the part number I was viewing got deleted. Ray Quote Link to comment https://forums.phpfreaks.com/topic/36689-solved-loop-not-working/#findComment-174941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.