Well i have generate buttons. Their function are the same which is when i clicked it , it will do the calculations. the problem is when i clicked the second generate button, it will do the calculations for the first one and same goes to third button and so on. what i want is, each generate button will only do calculation for their own job. Can anyone help me ?
my generate button
And below is the code :
<tr>
<td></td>
<td></td>
<td style="font-family:centruy-gothic"<strong><font color = "black">
<?echo $listb['task_name'];?>
<input type="hidden" name="pc_id[]" value="<? echo $pc_id;?>" >
<input type="hidden" name="ps_id[]" value="<? echo $ps_id;?>" >
</font></strong></td>
<td align="center" style="font-family:century gothic"><input type="text" id ="task_mark" class="input-medium" name="task_mark[]" value="<? echo $listb['task_mark'];?>" onchange="getDate()"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="marking" class="input-medium" name="marking[]" value="<? echo $listb['marking'];?>"onchange="getDate()"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="destination_marking" class="input-medium" name="destination_marking[]" value="<? echo $listb['destination_marking'];?>"onchange="getDate()"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="days" class="input-medium" name="days[]" value="<? echo $listb['days'];?>"onchange="getDate()"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="duration" class="input-medium" name="duration[]" value="<? echo $listb['duration'];?>" onchange="calc()"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="start_date" class="input-long" name="start_date[]" value="<? echo $listb['start_date'];?>" class="date demo" onchange="getDate()" ></td>
<td align="center" style="font-family:century gothic"><input type="text" id="end_date" class="input-long" name="end_date[]" value="<? echo $listb['end_date'];?>" class="date demo" onchange="getDate()"></td>
<td align="center" ><input class="submit-green" id="end_date" type="button" name="end_date[]" value="GENERATE" onclick="getDate()"></td>
</tr>
And here's the script
<script>
function getDate()
{
var sd = document.getElementById('start_date').value;
var dura = document.getElementById('duration').value;
var m = document.getElementById('marking').value;
var date = new Date(sd);
var newdate = new Date (date);
var durations = parseInt(dura);
var markings = parseInt(m);
if (markings === 1)
{
newdate.setDate(newdate.getDate());
}
else if (markings === 2)
{
newdate.setDate(newdate.getDate() + durations);
}
else if (markings === 3)
{
newdate.setDate((newdate.getDate() + durations) + 1 );
}
var dd = newdate.getDate();
var mm = newdate.getMonth()+1;
var y = newdate.getFullYear();
var someFormattedDate = y + '-' + mm +'-' + dd;
document.getElementById('end_date').value = someFormattedDate;
}
</script>
You can give a parameter in the html code modifying the onchange="getDate()" like this:
<td align="center" style="font-family:century gothic"><input type="text" id ="task_mark" class="input-medium" name="task_mark[]" value="<? echo $listb['task_mark'];?>" onchange="getDate(1)"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="marking" class="input-medium" name="marking[]" value="<? echo $listb['marking'];?>"onchange="getDate(2)"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="destination_marking" class="input-medium" name="destination_marking[]" value="<? echo $listb['destination_marking'];?>"onchange="getDate(3)"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="days" class="input-medium" name="days[]" value="<? echo $listb['days'];?>"onchange="getDate(4)"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="duration" class="input-medium" name="duration[]" value="<? echo $listb['duration'];?>" onchange="calc()"/></td>
<td align="center" style="font-family:century gothic"><input type="text" id="start_date" class="input-long" name="start_date[]" value="<? echo $listb['start_date'];?>" class="date demo" onchange="getDate(5)" ></td>
<td align="center" style="font-family:century gothic"><input type="text" id="end_date" class="input-long" name="end_date[]" value="<? echo $listb['end_date'];?>" class="date demo" onchange="getDate(6)"></td>
<td align="center" ><input class="submit-green" id="end_date" type="button" name="end_date[]" value="GENERATE" onclick="getDate(7)"></td>
Then, in the script you get the parameter to do different things:
<script>
function getDate(param)
{
And now you now wich of the button he checked
I assume you have a foreach before your table rows.
In this case u have several times the same id for each input field.
Try to make the id's unique. Something like this:
<input type="text" id ="task_mark_row1">
//next table row:
<input type="text" id ="task_mark_row2">
...
Related
Screenshot:
I want to add the same value to a table row input field, but JavaScript working for first row only. Please help me with this .
My table is
<tr align="center">
<td align="center"><input type="checkbox" name="prodid[]" value="<?php echo $row["name"]; ?>"></td>
<td align="center"><?php echo $row["name"]; ?>
<input type="hidden" name="prodname[]" value="<?php echo $row["name"]; ?>">
</td>
<td align="center"><input align="center" type="number" name="prod_price[]" value="<?php echo $row["price"]; ?>" class="form-control"><input type="hidden" class="iprice" value="<?php echo $row["price"]; ?>"></td>
<td align="center"><input type="number" class="form-control iquantity" onchange="Subtotal()" type="number" name="prod_qty[]" class="form-control"></td>
<td align="center"><input type="number" class="eachnumber" id="eachnumber" name="prodsname[]" ></td>
<td class="itotal" align="center">0</td>
</tr>
passes the value from
<input type="number" id="number" class="form-control form-control-solid ps-12" placeholder="number"/>
javascript
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js" integrity="sha512-jGR1T3dQerLCSm/IGEGbndPwzszJBlKQ5Br9vuB0Pw2iyxOy+7AK+lJcCC8eaXyz/9du+bkCy4HXxByhxkHf+w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.js" integrity="sha512-1icA56H/QfnWMmygJLor4dORvI+7Kurg9CfXSDeJmyMJQL98LfPRk/UwCmi7NoZwbUwxMoI0tc2gJqG/Uu+ecA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
$('#number').change(function() {
for (i = 0; i < eachnumber.length; i++) {
$('#eachnumber').val($(this).val());
}
});
</script>
If you want to add that value in eachnumber of all the rows then you can simply do this.
$('#number').change(function() {
$('.eachnumber').val($(this).val());
});
I have the following table row:
<tr class="table-row">
<td class="column-1">
<div class="cart-img-product b-rad-4 o-f-hidden">
<img src="../admin/uploads/<?php echo $info['product_photo']; ?>" alt="IMG-PRODUCT">
</div>
</td>
<td class="column-2">
<?php echo $info['product_name']; ?>
</td>
<td class="column-3"><input type="text" value="<?php echo $info['product_price']; ?>" readonly></td>
<td class="column-4"><input type="text" value="<?php echo $info['product_amount']; ?> Piece" readonly></td>
<td class="column-5"><input style="color:red;" type="text" value="Rs <?php echo $info['product_price']*$info['product_amount']; ?>" readonly></td>
</tr>
I want to get the sum of the last td which will be the total pricing. I thought of using js but as the row may get dynamically added it is hard. How can i get the total price.
I want the total to be displayed here.
<span class="m-text21 w-size20 w-full-sm">
<strong><input type="text" id="total" value=""></strong>
</span>
You can try with querySelectorAll() and forEach() like the following way:
var lastTDs = document.querySelectorAll('tbody tr td:last-child input');
var sum = 0;
[...lastTDs].forEach(function(td) {
sum += Number(td.value.split(' ')[1]);
});
console.log(sum);
<table>
<tbody>
<tr class="table-row">
<td class="column-1">
<div class="cart-img-product b-rad-4 o-f-hidden">
<img src="../admin/uploads/<?php echo $info['product_photo']; ?>" alt="IMG-PRODUCT">
</div>
</td>
<td class="column-2"><?php echo $info['product_name']; ?></td>
<td class="column-3"><input type="text" value="<?php echo $info['product_price']; ?>" readonly></td>
<td class="column-4"><input type="text" value="<?php echo $info['product_amount']; ?> Piece" readonly></td>
<td class="column-5"><input style="color:red;" type="text" value="Rs 50" readonly></td>
</tr>
<tr class="table-row">
<td class="column-1">
<div class="cart-img-product b-rad-4 o-f-hidden">
<img src="../admin/uploads/<?php echo $info['product_photo']; ?>" alt="IMG-PRODUCT">
</div>
</td>
<td class="column-2"><?php echo $info['product_name']; ?></td>
<td class="column-3"><input type="text" value="<?php echo $info['product_price']; ?>" readonly></td>
<td class="column-4"><input type="text" value="<?php echo $info['product_amount']; ?> Piece" readonly></td>
<td class="column-5"><input style="color:red;" type="text" value="Rs 100" readonly></td>
</tr>
</tbody>
</table>
try
let v = [...document.querySelectorAll('.column-5 input')];
total.value = v.reduce((a,c)=> +c.value.replace(/Rs /,'')+a, 0)
We use here standard: querySelectorAll, reduce, arrow functions, spread syntax (to cast NodeList to array - to have access to reduce), replace with simple regular expression (to remove Rs prefix). The v contains array with <input> elements from last column for all rows. By+ in +c.val.. JS make implicit cast string to number.
let v = [...document.querySelectorAll('.column-5 input')];
total.value = v.reduce((a,c)=> +c.value.replace(/Rs /,'')+a, 0)
<table><tbody>
<tr class="table-row">
<td class="column-1">
<div class="cart-img-product b-rad-4 o-f-hidden">
<img src="../admin/uploads/xxx" alt="IMG-PRODUCT">
</div>
</td>
<td class="column-2">
<?php echo $info['product_name']; ?>
</td>
<td class="column-3"><input type="text" value="10000" readonly></td>
<td class="column-4"><input type="text" value="2 Piece" readonly></td>
<td class="column-5"><input style="color:red;" type="text" value="Rs 20000" readonly></td>
</tr>
<tr class="table-row">
<td class="column-1">
<div class="cart-img-product b-rad-4 o-f-hidden">
<img src="../admin/uploads/xxx" alt="IMG-PRODUCT">
</div>
</td>
<td class="column-2">
<?php echo $info['product_name']; ?>
</td>
<td class="column-3"><input type="text" value="14000" readonly></td>
<td class="column-4"><input type="text" value="1 Piece" readonly></td>
<td class="column-5"><input style="color:red;" type="text" value="Rs 14000" readonly></td>
</tr>
<tbody><table>
<span class="m-text21 w-size20 w-full-sm">
<strong><input type="text" id="total" value=""></strong>
</span>
I have created a dynamic form and I am trying to send the form data to mysql through PHP but its not working. Data is not getting sent even from the very first row without adding a dynamic row. I'm new to this topic, so I'm out of ideas to solve it. How can I make this form a correct one and send accurate data to mysql?
In my form I have 3 fields that are not dynamic.
Here is the form code:
<form name="newbillform" method="POST" action="save_purchase_details.php">
<table style=" border:1px solid black" cellpadding="5px" cellspacing="0px" align="center" border="0">
<tr>
<td colspan="4" style="background:#0066FF; color:#FFFFFF; fontsize:20px" align="center">
ADD NEW PURCHASE RECORD
</td>
</tr>
<tr>
<td>Date:</td>
<td>
<input type="date" name="p_date"/>
</td>
</tr>
<tr>
<td>Invoice Number:</td>
<td>
<input type="text" name="invoice_no" size="50">
</td>
</tr>
<tr>
<td>Balance:</td>
<td>
<input type="text" name="balance" size="50">
</td>
</tr>
</table>
<h2 style="padding-left:10px;">Enter Product Details Below:-</h2>
<table id="product_details" style="margin-top:8px;" align='center' border='1' width="900px">
<tr id="row1">
<td>
<input type="text" name="qty[]" value="" placeholder="Quantity" size="6">
</td>
<td>
<input type="text" name="pack[]" value="" placeholder="Pack" size="6">
</td>
<td>
<input type="text" name="item_name[]" value="" placeholder="Item Name" size="16">
</td>
<td>
<input type="text" name="batch[]" value="" placeholder="Batch" size="6">
</td>
<td>
<input type="text" name="expiry[]" value="" placeholder="Expiry" size="6">
</td>
<td>
<input type="text" name="mrp[]" value="" placeholder="M.R.P" size="6">
</td>
<td>
<input type="text" name="rate[]" value="" placeholder="Rate" size="6">
</td>
<td>
<input type="text" name="vat[]" value="" placeholder="VAT" size="6">
</td>
<td>
<input type="text" name="discount[]" value="" placeholder="Discount" size="6">
</td>
<td>
<input type="button" class="button-add-row" onclick="add_row();" value="ADD ROW" size="8">
</td>
</tr>
</table>
<center>
<input type="submit" name="submit_row" value="SUBMIT">
</center>
</form>
Here is the javascript code:
<script type="text/javascript">
function add_row()
{
$rowno = $("#product_details tr").length;
$rowno = $rowno + 1;
$("#product_details tr:last").after("<tr id='row"+$rowno+"'><td><input type='text' name='qty[]' placeholder='Quantity' size='6'></td><td><input type='text' name='pack[]' placeholder='Pack' size='6'></td><td><input type='text' placeholder='Item Name' name='item_name[]' size='16'></td><td><input type='text' name='batch[]' placeholder='Batch' size='6'></td><td><input type='text' name='expiry[]' placeholder='Expiry' size='6'></td><td><input type='text' name='mrp[]' placeholder='M.R.P' size='6'></td><td><input type='text' name='rate[]' placeholder='Rate' size='6'></td><td><input type='text' name='vat[]' placeholder='VAT' size='6'></td><td><input type='text' name='discount[]' placeholder='Discount' size='6'></td><td><input type='button' class='button-add-row' value='DELETE' onclick=delete_row('row"+$rowno+"')></td></tr>");
}
function delete_row(rowno)
{
$('#'+rowno).remove();
}
</script>
Here is the PHP code:
<?php
$connect = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("store_records",$connect) or die(mysql_error());
if(isset($_POST['submit_row']))
{
$amount;
$grand_total;
for($i = 0; $i < count($_POST['item_name']); $i++)
{
$qty = $_POST['qty'][$i];
$p_date = $_POST['p_date'];
$invoice_no = $_POST['invoice_no'];
$balance = $_POST['balance'];
$pack = $_POST['pack'][$i];
$item_name = $_POST['item_name'][$i];
$batch = $_POST['batch'][$i];
$expiry = $_POST['expiry'][$i];
$mrp = $_POST['mrp'][$i];
$rate = $_POST['rate'][$i];
$vat = $_POST['vat'][$i];
$discount = $_POST['discount'][$i];
$amount = $balance+($qty*$rate)-$discount;
$grand_total = $amount+(($amount*$vat)/100);
$query =mysql_query("insert into bill_records values('', '$p_date', '$invoice_no', '$balance', '$qty','$pack','$item_name', '$batch', '$expiry', '$mrp', '$rate', '$vat', '$discount', '$amount', '$grand_total')");
}
}
?>
It would be of great help. Thank You..
Hi I am using codeigniter framework. I am having a javascript to to create a table row dynamically when I click a button.
I need to have a dropdown inside a table cell that is added dynamically. Here is the code I tried so far.
function displayResult() {
<?php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach ($employee as $row)
{
$options_employee[$row['first_name']] = $row['first_name'];
}
?>
var something='<?php echo form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');?>';
alert(something);
var row = document.getElementById("test").insertRow(-1);
row.innerHTML = '<td><div>'+something+'</div></td><td><input type="text" name="start_time[]" value="" style="width:35px;"/></td><td><input type="text" name="pid[]" style="width:35px;"/></td><td><input type="text" name="description[]" class="description" value="" style="width:145px;"/></td><td><input type="text" class="type" value="" style="width:45px;"/></td><td><input type="text" class="qty_prch" value="" style="width:45px;"/></td><td><input type="text" class="qty_used" value="" style="width:45px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td>';
}
When button is clicked I call this displayResult(). I am getting 2 errors in my console.
1.Uncaught SyntaxError: Unexpected token ILLEGAL
2.Uncaught ReferenceError: displayResult is not defined
Can someone help me? Please help me fix this code.
function displayResult() { <? php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach($employee as $row) {
$options_employee[$row['first_name']] = $row['first_name'];
}
?>
var something = '<?php echo form_dropdown('
employee ', $options_employee, set_value('
employee[]
'), '
class = "span2"
');?>';
alert(something);
var row = document.getElementById("test").insertRow(-1);
row.innerHTML = '<td><div>' + something + '</div></td><td><input type="text" name="start_time[]" value="" style="width:35px;"/></td><td><input type="text" name="pid[]" style="width:35px;"/></td><td><input type="text" name="description[]" class="description" value="" style="width:145px;"/></td><td><input type="text" class="type" value="" style="width:45px;"/></td><td><input type="text" class="qty_prch" value="" style="width:45px;"/></td><td><input type="text" class="qty_used" value="" style="width:45px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td>';
}
<div id="form">
<!-- div form starts here.its for add table -->
<table id="test">
<thead>
<tr>
<td style="width:80px;">
employee
</td>
<td style="width:35px;">
start time
</td>
<td style="width:35px;">
id
</td>
<td style="width:145px;">
Description
</td>
<td style="width:45px;">
Type
</td>
<td style="width:45px;">
qty prch
</td>
<td style="width:45px;">
qty used
</td>
<td style="width:70px;">
Price
</td>
<td style="width:70px;">
discount
<td style="width:70px;">
Tax
</td>
<td style="width:70px;">
Total
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php echo form_dropdown( 'employee', $options_employee, set_value( 'employee[]'), 'class="span2"');?>
</td>
<td>
<input type="text" name="start_time[]" value="" style="width:35px;" />
</td>
<td>
<input type="text" name="pid[]" value="" style="width:35px;" />
</td>
<td>
<input type="text" name="description[]" class="description" value="" style="width:145px;" />
</td>
<td>
<input type="text" name="type[]" class="type" style="width:45px;" />
</td>
<td>
<input type="text" name="qty_prch[]" class="qty_prch" style="width:45px;" />
</td>
<td>
<input type="text" name="qty_used[]" class="qty_used" style="width:45px;" />
</td>
<td>
<input type="text" name="price[]" class="price" style="width:70px;" />
</td>
<td>
<input type="text" name="discount[]" class="discount" style="width:70px;" />
</td>
<td>
<input type="text" name="tax[]" class="tax" style="width:70px;" />
</td>
<td>
<input type="text" name="total[]" class="total" style="width:70px;" />
</td>
</tr>
</tbody>
</table>
<div id="add_row">
<button onClick="displayResult()" class="add_r"></button>
</div>
This works fine for me. Thank you all for your support !!
function displayResult() {
<?php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach ($employee as $row)
{
$options_employee[$row['first_name']] = $row['first_name'];
}
$dropdown = form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');
?>
var complex = <?php echo json_encode($dropdown); ?>;
var row = document.getElementById("test").insertRow(-1);
row.innerHTML =
'<td><div>'+complex+'</div></td>'+
'<td><input type="text" name="start_time[]" value="" style="width:35px;"/></td>'+
'<td><input type="text" name="pid[]" style="width:35px;"/></td>'+
'<td><input type="text" name="description[]" class="description" value="" style="width:145px;"/></td>'+
'<td><input type="text" class="type" value="" style="width:45px;"/></td>'+
'<td><input type="text" class="qty_prch" value="" style="width:45px;"/></td>'+
'<td><input type="text" class="qty_used" value="" style="width:45px;"/></td>'+
'<td><input type="text" value="" style="width:70px;"/></td>'+
'<td><input type="text" value="" style="width:70px;"/></td>'+
'<td><input type="text" value="" style="width:70px;"/></td>'+
'<td><input type="text" value="" style="width:70px;"/></td>';
}
Change your single ' to double "
your code is var something='<?php echo form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');?>';
because when javascript start reading this line
var something='<?php echo form_dropdown('employee' it seems statement end here ('e near ' after dropdown('
you should use something like that
var something='<?php echo form_dropdown("employee", $options_employee, set_value("employee[]"), \'class="span2"\');?>';
sorry for my bad english
In your code Snippet on the first line :
function displayResult() { <? php
there is a space between <? and php
Remove that and retry.
I have a form that is being used to generate an email template. At the bottom of the page I have a table that displays the email name, and which departments have access to use it. Ultimately what I want to happen is make the name of the email at the bottom of the page to act like a button. When the user clicks on the email name, it will grab those values from the DB and pass them into the appropriate input field. Below is a sample of my current PHP code. If someone could provide a suggestion or even an example I would be grateful.
This is the form for the email template setup:
<form id="Email" name="Email" method='post' action="<?php echo htmlspecialchars($_SERVER['PHP']);?>">
<fieldset style="width: auto; height: auto;">
<legend class="legend1"><h2> Manage E-Mails </h2></legend>
<table width="100%" style="text-align:center">
<tr>
<td width="60%" style="text-align: left;">
<input type="text" id="name" name="name" placeholder="Email Template Name" value="" maxlength="100" style="width: 250px; height: 20px;"/>
<input type="radio" name="from" id="from" value="user" />Send From User
</td>
</tr>
<tr>
<td style="text-align: left;">
<input type="text" style="width:250px; height: 20px; visibility: hidden;" />
<input type="radio" name="from" id="from" value="department" />Send From Department
</td>
</tr>
<tr>
<td style="text-align: left;">
<input type="text" id="To" name="To" placeholder="To: " value="" maxlength="250" style="width: 250px; height: 20px;"/>
<input type="checkbox" name="user" id="user" value="YES" />Autocopy User
<?php echo " ";?><input type = "checkbox" name="escalate" id="escalate" value="YES" />Make Escalated Email Only
</td>
</tr>
<tr>
<td style="text-align: left;">
<input type="text" id="CC" name="CC" placeholder="CC: " value="" maxlength="100" style="width: 250px; height: 20px;"/>
<input type="checkbox" name="customer" id="customer" value="YES" />Autocopy Customer
</td>
</tr>
<tr>
<td style="text-align: left;">
<input type="text" id="BCC" name="BCC" placeholder="BCC: " value="" maxlength="100" style="width: 250px; height: 20px;"/>
<input type="checkbox" name="additional" id="additional" value="YES" />Allow Additional Email Address(es)
</td>
</tr>
<tr>
<td colspan=2 style="text-align: left;">
<input type="text" id="subject" name="subject" placeholder="Subject " value="" maxlength="100" style="width: 400px; height: 20px;"/>
Keywords
</td>
</tr>
<tr>
<td style="text-align: left;">
<textarea name="content" maxlength="3000" cols="100" rows="12"></textarea>
</td>
</tr>
</table>
<input type="submit" name="submit" value="Submit" style="float: left;">
</fieldset>
</form>
This is the form that allows users to update what department the email will belong to. This where it will display the email name. I want the email name to be clickable and to generate the info back into the table above.
<form id = "Display_Email" name="Display_Email" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP']);?>">
<?php
$get_business = mysql_query("SELECT bus_name, bus_id FROM business where bus_id = '{$_SESSION['bus_id']}'");
while(($business = mysql_fetch_assoc($get_business)))
{
echo '
<h3>'.$business['bus_name'].'</h3>
<table class="departments">
<tr>
<th scope="col" style="width: 175px;">Email Name</th>
';
$get_depts = mysql_query("SELECT dept_name FROM depts where bus_id = '{$_SESSION['bus_id']}'");
while(($department = mysql_fetch_assoc($get_depts)))
{
echo '
<th scope="col" style="width: 175px;">'.$department['dept_name'].'</th>
';
}
echo '
</tr>
';
$get_emails = mysql_query("SELECT id, email_name from emails where bus_id = '{$_SESSION['bus_id']}' ORDER BY email_name ASC");
while(($email = mysql_fetch_assoc($get_emails)))
{
echo '
<tr>
<td>'.$email['email_name'].'</td>
';
$get_depts = mysql_query("SELECT dept_name, dept_id FROM depts where bus_id = '{$_SESSION['bus_id']}'");
while(($department = mysql_fetch_assoc($get_depts)))
{
$get_email_dept = mysql_query("SELECT dept_id from emails where id = '{$email['id']}'");
while(($email_dept = mysql_fetch_assoc($get_email_dept)))
{
$departments = explode(",", $email_dept['dept_id']);
if(in_array($department['dept_id'], $departments, TRUE))
{
echo '<input type="hidden" name="Email_Box[]" value="0">';
echo '<td><input type="checkbox" name="Email_Box[]" value="'.$department['dept_id'].'" checked="checked""></td>';
}
else
{
echo '<input type="hidden" name="Email_Box[]" value="0">';
echo '<td><input type="checkbox" name="Email_Box[]" value="'.$department['dept_id'].'"></td>';
}
}
}
echo '
</tr>
';
}
echo '
</table>
';
}
?>
<input type="submit" name="Email_Submit" value="Submit" style="float: left;"/>
</form>