Problem in counting row to get the correct qty per item
Hi..
I have problem in getting the DemandedQty that was input. Only in the Demanded Qty of P28 items was read.
For example I input 21 in Demanded Qty of P28 and then It alerts 21, but when I input 2 in Demanded Qty of P30 the alert was 21. It means only the P28 Demanded Qty was get.
here is my code:
PHP Code:
<?php
error_reporting(0);
date_default_timezone_set("Asia/Singapore"); //set the time zone
$con = mysql_connect('localhost', 'root','');
<script type="text/javascript">
function showSum(element) {
var clickElement = element.value;
var click_id = element.id;
var Table = document.getElementById('list');
var rows = Table.rows;
var strSelect = document.getElementById(click_id).value;
alert(strSelect); // i tried to alert to check if he gets the correct value, but I found that only the Demanded Qty of P28 was read. And when I try to input on another Demanded Qty like in P30 the alert was blank.
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
First of all you are using way to much database resources by running so many queries.
$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
$sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items" or die(mysql_error());
What is the point of running the first query when the same Items values can be obtained by the second query.
I am guessing you just want to make sure this row
<tr>
<td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items_[$rowCounter]' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
<td style='border:none;'> </td>
<td style='border:none;'> </td>
<td style='border: none;'><center><input type='text' style='text-align: right;' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup ='showSum(this);'></center></td>
</tr>
is not duplicated.
//=============================================================================
How about this
If you run only the second query instead, you can just check that the Items value is different to echo that row.
$res= mysql_query($sql, $con);
$CurrentItems='';
$rowCounter=mysql_num_rows($res); //gives you the total number of rows returned by a query
/*on the next iteration that row will not be echoed again if the next $Items is the same as before */
$CurrentItems=$Items;
}
As for the problem of Javascript, the value you are looking for is "element.value".
clickElement is misleading because it's not the element clicked on by its value.
The var strSelect = document.getElementById(click_id).value; should be written insted:
var strSelect = element.value;
First of all you are using way to much database resources by running so many queries.
$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
$sql = "SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = '$Items' ORDER BY Items" or die(mysql_error());
What is the point of running the first query when the same Items values can be obtained by the second query.
I am guessing you just want to make sure this row
<tr>
<td style='border: none;font-weight: bold;'> <input type='name' value='$Items_' name='Items_[]' id='Items_[$rowCounter]' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;'></td>
<td style='border:none;'> </td>
<td style='border:none;'> </td>
<td style='border: none;'><center><input type='text' style='text-align: right;' name='DemandedQty[]' id='DemandedQty' value='' size='12' onkeyup ='showSum(this);'></center></td>
</tr>
is not duplicated.
//=============================================================================
How about this
If you run only the second query instead, you can just check that the Items value is different to echo that row.
$res= mysql_query($sql, $con);
$CurrentItems='';
$rowCounter=mysql_num_rows($res); //gives you the total number of rows returned by a query
/*on the next iteration that row will not be echoed again if the next $Items is the same as before */
$CurrentItems=$Items;
}
As for the problem of Javascript, the value you are looking for is "element.value".
clickElement is misleading because it's not the element clicked on by its value.
The var strSelect = document.getElementById(click_id).value; should be written insted:
var strSelect = element.value;
Bookmarks