<?php 
include('config.php');
$penerbit = $_POST['penerbit'];


if($penerbit){$query_p = " WHERE penerbit = '$penerbit'";}
?>
    <table class=" table-hover table-bordered table table-condensed">
    <thead>
    	<tr class="bold">
        	<td style="width:50px">No</td>
        	<td style="width:80px;">Code</td>
            <td>Product Name</td>
            <td style="width:250px">Vendor</td>
            <td style="width:120px">S. Price</td>
            <td style="width:100px">Category</td>
            <td style="width:100px">Featured</td>
        </tr>
        </thead>

		<tbody>

<?php
$i = 0;
   	$sql = "SELECT * FROM mst_product $query_p   ORDER BY pm_name";
	$sql_con = $conn->query($sql) or die($sql);
	while($rs = $sql_con->fetch_assoc()){
		
	$id = $rs['pm_autoid'];
	
	$sqld = "SELECT * FROM dl_product_category a, product_category b WHERE product_id = '$id'";
	$dcond = $conn->query($sqld) or die($sqld);
	$rowd = $dcond->fetch_array();
	$sc_autoid = $rowd['sc_autoid'];

?>
        <tr class="rec_body">
        	<td><?php echo $i+1?></td>
        	<td><?php echo $rs['pm_code']?></td>
            <td><?php echo $rs['pm_name']?></td>
            <td><?php echo $_ven_name[$rs['ven_autoid']]?></td>
			<td class="tr"><?php echo number_format($rs['pm_sprice'])?></td>
            <td class="tc">
            	<select class="input" name="sc_autoid<?php echo $i?>" id="sc_autoid" style="width:150px">
                <option value="">Select Category</option>
                <?php
                $sqlsc = "select * from product_category a, product_subcategory b  
						WHERE a.pc_autoid = b.pc_autoid order by a.pc_name";
				$sc_con = $conn->query($sqlsc) or die($sqlsc);
				while($rsc = $sc_con->fetch_assoc()){
				?>
                	<option <?php if($sc_autoid==$rsc['sc_autoid']){echo "selected='selected'";}?> 
                    value="<?php echo ($rsc['pc_autoid'].','.$rsc['sc_autoid'])?>"><?php echo $rsc['pc_name']?> | <?php echo $rsc['sc_name']?></option>
                <?php } ?>
                </select>
                <input type="hidden" name="pm_autoid<?php echo $i?>" value="<?php echo $id?>">
            </td>
			<td class="tc">
				<label class="chk_container mr-3">
				  <input type="checkbox" name="featured_flag<?php echo $i?>" value="Y" <?php if($rs['featured_flag']=="Y"){echo 'checked="checked"';}?>>
				  <span class="chk_checkmark"></span>
				</label>
            </td>
        </tr>

<?php 
$i = $i+ 1 ;
} ?>
</tbody>
</table>
<input type="hidden" name="row" value="<?php echo $i?>">