Forum Moderators: coopster
<?php
$color1 = "#D7DFFF";
$color2 = "#F3F3F3";
$row_count = 0;
while($row=mysql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr style="background-color:<?php echo $row_color ?>;">
<td><?=$row['scrapped_date_in']?></td>
<td><?=$row['scrapped_date_scrapped']?></td>
<?php $manufacturer = $row['scrapped_make'];
$sql_man="SELECT * FROM manufacturer WHERE manufacturer_id = '".$manufacturer."'";
$res_man = mysql_query($sql_man) or die(mysql_error());
?>
<td><?=$res_man['manufacturer_name']?></td>
<td><?=$row['scrapped_model']?></td>
<td><?=$row['scrapped_registration']?></td>
<td><?=$row['scrapped_entered_by']?></td>
<td><?=$row['scrapped_last_keeper']?></td>
</tr>
<?php $row_count++;
}?>
So the Manufacturer & Entered By fields are just an ID number from another table. I'd like to select the manufacturer name based on the ID and the same for the Entered By.
$sql="SELECT * FROM scrapped ORDER BY scrapped_date_logged ASC";
$result = mysql_query($sql) or die(mysql_error());
<table cellpadding="0" cellspacing="0" id="models">
<tr class="headings">
<th class="w100">Date In</th>
<th class="w100">Date Scrapped</th>
<th class="w140">Manufacturer</th>
<th class="w80">Model</th>
<th class="w80">Registration</th>
<th class="w140">Entered By</th>
<th class="w90">Last Keeper</th>
</tr>
<?php
$color1 = "#D7DFFF";
$color2 = "#F3F3F3";
$row_count = 0;
while($row=mysql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr style="background-color:<?php echo $row_color ?>;">
<td><?=$row['scrapped_date_in']?></td>
<td><?=$row['scrapped_date_scrapped']?></td>
<?php $manufacturer = $row['scrapped_make'];
$sql_man="SELECT * FROM manufacturer WHERE manufacturer_id = '".$manufacturer."'";
$res_man = mysql_query($sql_man) or die(mysql_error());
?>
<td><?=$res_man['manufacturer_name']?></td>
<td><?=$row['scrapped_model']?></td>
<td><?=$row['scrapped_registration']?></td>
<td><?=$row['scrapped_entered_by']?></td>
<td><?=$row['scrapped_last_keeper']?></td>
</tr>
<?php $row_count++;
}?>
</table>
<?php $manufacturer = $row['scrapped_make'];
$sql_man="SELECT manufacturer_name FROM manufacturer WHERE manufacturer_id = '".$manufacturer."'";
$res_man = mysql_query($sql_man) or die(mysql_error());
if ($row2 = mysql_fetch_array($res_man)) { // no need for while, should only be one, right?
$manvalue = $row2['manufacturer_name'];
}
else { $manvalue = 'N/A'; }
?>
<td><?php echo $manvalue;?></td>
<td><?php echo $row['scrapped_model'];?></td>
<td><?php echo $row['scrapped_registration'];?></td>
<td><?php echo $row['scrapped_entered_by'];?></td>
<td><?php echo $row['scrapped_last_keeper'];?></td>
</tr>
<?php
$color1 = "#D7DFFF";
$color2 = "#F3F3F3";
$row_count = 0;
while($row=mysql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr style="background-color:<?php echo $row_color ?>;">
<td><?=$row['scrapped_date_in']?></td>
<td><?=$row['scrapped_date_scrapped']?></td>
<?php $manufacturer = $row['scrapped_make'];
$sql_man="SELECT manufacturer_name FROM manufacturer WHERE manufacturer_id = '".$manufacturer."'";
$res_man = mysql_query($sql_man) or die(mysql_error());
if ($row2 = mysql_fetch_array($res_man)) {
$manvalue = $row2['manufacturer_name'];
}
else { $manvalue = 'N/A'; }
?>
<td><?php echo $manvalue;?></td>
<td><?=$row['scrapped_model']?></td>
<td><?=$row['scrapped_registration']?></td>
<?php $employee = $row['scrapped_entered_by'];
$sql_emp="SELECT employee_name FROM employees WHERE employee_id = '".$employee."'";
$res_emp = mysql_query($sql_emp) or die(mysql_error());
if ($row3 = mysql_fetch_array($res_emp)) {
$empvalue = $row3['employee_name'];
}
else { $empvalue = 'N/A'; }
?>
<td><?php echo $empvalue;?></td>
<td><?=$row['scrapped_last_keeper']?></td>
</tr>
<?php $row_count++;
}?>
</table>
<?php } ?>