Jump to content

funbinod

Members
  • Posts

    501
  • Joined

  • Last visited

Everything posted by funbinod

  1. yes! i had made logic to this also. but there is also the same problem. lets imagine the same example data i gave above. purchase table date qty rate amt 2014-01-01 3 20 60 2014-01-02 5 21 106 2014-01-03 3 22 66 in this, if i sold '4' units then how can i subtract from the rows to get remaining units? i've to subtract '3' units from first row and '1' unit from second row. and if i sell '10' units then i need to subtract '3' from first, '5' from second and '2' from third. this should keep on looping. and the problem for me is how can i loop the process till i get the required condition? i've thought of another table also, but not temporary, to record and update with each purchases and sales. first insert purchase record and after each sales update the rows by subtracting the units. and the problem is same.... i've made logic to the process. but i couldn't make logic with php...
  2. thats the exact problem. i am not getting any idea to do this. i couldn't make the loop function for this. its being tough. thats why i'm asking for help here...
  3. i think its because u r inserting the data ONLY to the row which belongs to the user u log in.....
  4. because there are multiple rows with different quantity and rate on different dates. and i just want to select the rows descending to meet the condition $cqty<= sum(qty). let me explain with this..... purchase table date qty rate amt 2014-01-01 3 20 60 2014-01-02 5 21 106 2014-01-03 3 22 66 now if $cqty is less than 3 i should select only last row, and if it is between 4 and 8, i should select last 2 rows. and if it is between 6 and 11 i should select all three rows and likewise.....
  5. hi all! am back with some try. please have a look and suggest. what i need to calculate is the amount starting from the last row of purchase table. if the $cqty is less than or equal to 'qty' on the last row then it should select the 'qty' and 'amt' from it. else if it is greater it should select one more row up (i.e. last two rows) and check if it matches the required case (i.e $cqty <= 'sum(qty)') and if true, select the sum of 'qty' and 'amt'. it should keep on moving upwards until it finds the required condition. but i couldn't make the loop for this. please help me to do this according the following..... $sid = 1;$cqty = 5; // this value is just for test and may change with the increase in transactions....$sql = mysqli_query($connect, "select qty, amt from purchase where sid=$sid order by date desc limit 1");while ($result = mysqli_fetch_object($sql)) { $qty = $result->qty; if ($cqty <= $qty) { $amt = $result->amt; echo $camt; } else if ($cqty > $qty) { $sql0 = mysqli_query($connect, "select sum(qty)qty, sum(amt)amt from purchase where sid=$sid order by date desc limit 2"); while ($result0 = mysqli_fetch_object($sql0)) { $qty = $result0->qty; if ($cqty <= $qty) { $amt = $result0->amt; $rate = $amt / $qty; echo $amt.':'.$rate.':'.$qty.'<br />'; echo $rate * $cqty.'<br />'; } } }}
  6. then how can i distinguish the data to know which table is the result coming from? like purchase.amt or sales.amt or likewise...???
  7. so what do u suggest me for this......
  8. i'm trying to union some tables but it is showing some errors here is what i wrote SELECT sum(amt) AS pamt FROM purchaseUNION SELECT sum(amt) AS samt FROM salesUNION SELECT sum(amt) AS ramt FROM receiptUNION SELECT sum(amt) AS ptamt FROM payment AS pt but it is selecting onle from first table (i.e. purchase) and for others it is saying "undefined index"
  9. my requirement is for the either case, as u said, from left to right and when it finds only one case TRUE it should stop checking further and execute the query. if ($col !== 'name') is true stop and execute the query. if ($col !== 'name') is false check if ($col !== 'item') is true and if it is true execute the query. and if both are false escape the query and move forward... could this be done with @Don Jajo's suggestion?
  10. i was trying to apply condition to some query to execute.. if ($col != 'name' or 'item') {// query would execute here} but it is not doing as expected. i want both conditions (or may be more) to execute the query but it is working only in first condition (i.e. $col != 'name') but not working for second (i.e. $col != 'item').. please guide me through
  11. i'm using jquery-2.1.0.js version. and so far the conflict somewhere concerns will u please check my script? i'll post my whole script here. i checked the page there and found some errors. i fixed all except CSSs. but the problem continues...
  12. its still the same issue document.getElementById('acregister').submit();document.getElementById('acregister').click(); $('#acregister').submit();$('#acregister').click(); both methods give same result... :'(
  13. upppsssss! sorry! now it says undefined
  14. ok! u can access the page on http://103.28.84.9/ac/acregister.php but if u find it to be online offline, please wait till i get online. coz this is the ip from my router (since i'm using public ip, my localhost can be accessed through this ip).
  15. but is it good idea? is there any other better idea? can u suggest me?
  16. <script>$(function () { 'use strict'; function confirmDialog(title, message, success) { var confirmdialog = $('<div></div>').appendTo('body').html('<div><h4>' + message + '</h4></div>').dialog ({ modal: true, title: title, zIndex: 10000, autoOpen: false, width: 'auto', resizable: false, buttons: { Yes: function () { success(); $(this).dialog("close"); }, No: function () { $(this).dialog("close"); } }, close: function() { console.log(this); $(this).remove(); } }); return confirmdialog.dialog("open"); } $('form').on('submit', function (e) { e.preventDefault(); var form = this; confirmDialog('Confirm', 'Are you sure?', function () {form.submit(); }); });});</script>
  17. thanks to u and congratulation to me.... i made it with simple change.. i was making while loop for just form elements. but i did it to a entire form and it worked... <?phprequire_once('mysql.php');$result = mysqli_query($connect, "SELECT * FROM tran WHERE svn=1");while ($row = mysqli_fetch_assoc($result)) { ?><form id="ajax-form" class="autosubmit" method="POST" action="./ajax-update.php"><label>SID:</label><input name="sid" value="<?php echo $row['sid'] ?>" /><label>srate:</label><input name="srate" value="<?php echo $row['srate'] ?>" /><label>sqty:</label><input name="sqty" value="<?php echo $row['sqty'] ?>" /><br /><br /><input id="where" type="hidden" name="svn" value="<?php echo $row['svn']; ?>" /><input id="where1" type="hidden" name="ssn" value="<?php echo $row['ssn']; ?>" /></form><?php } ?>
  18. uhh huh! it gives only the value from first row on both the conditions for all rows. i expected the second condition to be different as the different values from different rows. but it is selecting the same value for the second condition also...
  19. i dunno what i'm not doing right. i also expect it to log something. i also cleared the browser cache but it doesn't log anything. it just shows the typeerror on line 87...
  20. what could be the other actual SQL string other than $result = mysqli_query($connect, "UPDATE tran SET ".$col."='".$val."' WHERE ".$w_col."='".$w_val."' AND ".$w1_col."='".$w1_val."'") or die('Unable to update row.'.mysqli_error($connect)); ?? when i print($result) -- it alerts just '1' when i var_dump($result) -- it alerts 'string(1) "1" '
  21. it gives alert screen with just '1' in it when i print($result). and i cant understand what is it! and u r right i wish to add second condition to update each row. but result is not the same as i wish..
  22. oh sorry! here is the phps <?phprequire_once('mysql.php');$result = mysqli_query($connect, "SELECT * FROM tran WHERE svn=1");?><form id="ajax-form" class="autosubmit" method="POST" action="./ajax-update.php"><fieldset><legend>Update user information</legend><?while ($row = mysqli_fetch_assoc($result)) { ?><label>SID:</label><input name="sid" value="<?php echo $row['sid'] ?>" /><label>srate:</label><input name="srate" value="<?php echo $row['srate'] ?>" /><label>sqty:</label><input name="sqty" value="<?php echo $row['sqty'] ?>" /><br /><input id="where" type="hidden" name="svn" value="<?php echo $row['svn']; ?>" /><input id="where1" type="hidden" name="ssn" value="<?php echo $row['ssn']; ?>" /><?php } ?></fieldset></form> and here is ajax-update.php <?phprequire_once('mysql.php');function clean($value) { return $value;}if (count($_POST)) { foreach($_POST as $column => $value) ${$column} = clean($value); $result = mysqli_query($connect, "UPDATE tran SET ".$col."='".$val."' WHERE ".$w_col."='".$w_val."' AND ".$w1_col."='".$w1_val."'") or die('Unable to update row.'.mysqli_error($connect));}?>
  23. i cant understand what u meant. but the previous one updates the value to the mysql table for single row. and the second one also does but it updates the value of all the rows as the value of the last row (while trying to update multiple rows).....
  24. i learnt how to update single mysql row using jquery and ajax. now i want to learn how can i update multiple rows the same way. this was done to update one row -- var where_val = form.find('#where').val(); var where_col = form.find('#where').attr('name'); input.bind('blur', function(event) { var value = input.val(); $.ajax({ url: action, type: method, data: { val: value, col: column, w_col: where_col, w_val: where_val, }, to try if it works or not for updating multiple rows, i changed this to -- var where_val = form.find('#where').val(); var where_col = form.find('#where').attr('name'); var where1_val = form.find('#where1').val(); var where1_col = form.find('#where1').attr('name'); input.bind('blur', function(event) { var value = input.val(); $.ajax({ url: action, type: method, data: { val: value, col: column, w_col: where_col, w_val: where_val, w1_col: where1_col, w1_val: where1_val }, but somehow its not working. it is updating all the rows with the values of the last row. please guide me...
  25. its on same line as before ( line 87 )
×
×
  • Create New...