/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=php]
<?php
error_reporting(0);
date_default_timezone_set(“Asia/Singapore”); //set the time zone
$con = mysql_connect(‘localhost’, ‘root’,”);

if (!$con) {
echo ‘failed’;
die();
}

mysql_select_db(“mes”, $con);
?>
<html>
<title>Stock Requisition</title>
<head>
<link rel=”stylesheet” type=”text/css” href=”kanban.css”>

<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];

if (row.id.substr(0,3) == strSelect) {

}

}

}
</script>

</head>
<body>
<form name=”stock_requisition” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>
<div>
<table id=”list”>
<thead>
<th>Items</th>
<th>Sub Items</th>
<th>Item Code</th>
<th>Demanded Qty</th>
<th>UoM</th>
<th>Class</th>
<th>Description</th>
<th>BIN Location</th>
</thead>
<?php

$DemandedQty = $_POST[‘DemandedQty’];

$sql = “SELECT DISTINCT Items FROM bom_subitems ORDER BY Items”;
$res_bom = mysql_query($sql, $con);
$rowCounter = 1;
while($row = mysql_fetch_assoc($res_bom)){

$Items = $row[‘Items’];
$Items_ = substr($Items, 12, 3);

echo “<tr>
<td style=’border: none;font-weight: bold;’>&nbsp;<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;’>&nbsp;</td>
<td style=’border:none;’>&nbsp;</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>”;

$sql = “SELECT Items, SubItems, ItemCode, UoM, Class, Description, BINLocation, Quantity FROM bom_subitems WHERE Items = ‘$Items’ ORDER BY Items”or die(mysql_error());

$res_sub = mysql_query($sql, $con);
$rowCounter = 1;
while($row_sub = mysql_fetch_assoc($res_sub)){

$Items = $row_sub[‘Items’];
//$Items_ = substr($Items, 12, 3);
$SubItems = $row_sub[‘SubItems’];
$ItemCode = $row_sub[‘ItemCode’];
$UoM = $row_sub[‘UoM’];
$Class = $row_sub[‘Class’];
$Description = $row_sub[‘Description’];
$BINLocation = $row_sub[‘BINLocation’];
$Quantity = $row_sub[‘Quantity’];

echo “<input type=’hidden’ name=’Quantity’ id=’Quantity’ value=’$Quantity’>”;
echo “<tr>
<td style=’border: none;’>&nbsp;<input type=’hidden’ value=’$Items’ id=’Items[$rowCounter]’ name=’Items[]’></td>
<td style=’border: none;’>&nbsp;<input type=’text’ name=’SubItems[]’ value=’$SubItems’ id=’SubItems’ readonly=’readonly’ style=’border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;’></td>
<td style=’border: none;’>&nbsp;<input type=’text’ name=’ItemCode[]’ value=’$ItemCode’ id=’ItemCode’ readonly=’readonly’ style=’border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;’></td>
<td style=’border: none;’><center><input type=’text’ name=’SubQty[]’ id=’SubQty[$rowCounter]’ value=” size=’12’ style=’border:none;text-align: right;’></center></td>
<td style=’border: none;’ size=’3′>&nbsp;<input type=’text’ name=’UoM[]’ value=’$UoM’ id=’UoM’ readonly=’readonly’ style=’border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;’ size=’3′></td>
<td style=’border: none;’>&nbsp;<input type=’text’ name=’Class[]’ value=’$Class’ id=’Class’ readonly=’readonly’ style=’border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;’></td>
<td style=’border: none;’>&nbsp;<input type=’text’ name=’Description[]’ value=’$Description’ id=’Description’ readonly=’readonly’ style=’border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;’ size= ’30’></td>
<td style=’border: none;’>&nbsp;<input type=’text’ name=’BINLocation[]’ value=’$BINLocation’ id=’BINLocation’ readonly=’readonly’ style=’border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;’></td>
</tr>”;
$rowCounter = $rowCounter + 1;
}
$rowCounter = $rowCounter + 1;
}

?>
</table>
</div>
</form>
</body>
</html>

[/code]

Thank you so much

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@holyhttpMay 01.2012 — 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;'>&nbsp;<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;'>&nbsp;</td>

<td style='border:none;'>&nbsp;</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

while($row = mysql_fetch_assoc($res)){

$Items = $row['Items'];

$Items_ = substr($Items, 12, 3);

if($CurrentItems!=$Items){

<tr>

<td style='border: none;font-weight: bold;'>&nbsp;<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;'>&nbsp;</td>

<td style='border:none;'>&nbsp;</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>

}

...

...

...

...


/*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;
Copy linkTweet thisAlerts:
@newphpcoderauthorMay 02.2012 — 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;'>&nbsp;<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;'>&nbsp;</td>

<td style='border:none;'>&nbsp;</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

while($row = mysql_fetch_assoc($res)){

$Items = $row['Items'];

$Items_ = substr($Items, 12, 3);

if($CurrentItems!=$Items){

<tr>

<td style='border: none;font-weight: bold;'>&nbsp;<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;'>&nbsp;</td>

<td style='border:none;'>&nbsp;</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>

}

...

...

...

...


/*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;[/QUOTE]


Ok... I will try it..

Thank you
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...