Jump to content

funbinod

Members
  • Content Count

    486
  • Joined

  • Last visited

Community Reputation

3 Neutral

About funbinod

  • Rank
    Member
  • Birthday 05/12/1983

Contact Methods

  • Yahoo
    funbinod
  • Skype
    binod.anuj

Profile Information

  • Location
    Nepal

Previous Fields

  • Languages
    HTML, PHP, JAVASCRIPT

Recent Profile Visitors

5,484 profile views
  1. funbinod

    remove elements not in for loop range

    thank u. this suggestion solved the problem var remove = []; for (i=enclass; i<=12; i+=enclass) { remove.push(i); } if ($.inArray(parseInt($(this).parent("td").attr("class")), remove) == -1) { $(this).remove(); }
  2. hello all! i was trying to do a for loop to remove all elements that does not meet the for loop. following is the code i tried. $("#feetable input").each(function(e) { var thisvalue = $(this).val(); var enclass = 3; var i; for (i=enclass; i<=12; i+=enclass) { if ($(this).parent("td").attr("class") == i && $(this).val() == thisvalue) { $(this).remove(); } } }) and here is the html <td class='1'><input type='checkbox' /></td> <td class='2'><input type='checkbox' /></td> <td class='3'><input type='checkbox' /></td> <td class='4'><input type='checkbox' /></td> <td class='5'><input type='checkbox' /></td> <td class='6'><input type='checkbox' /></td> <td class='7'><input type='checkbox' /></td> <td class='8'><input type='checkbox' /></td> <td class='9'><input type='checkbox' /></td> <td class='10'><input type='checkbox' /></td> <td class='11'><input type='checkbox' /></td> <td class='12'><input type='checkbox' /></td> this removes the exact elemetns that the for loop finds (i.e. inputs under <td>s with class 3, 6, 9, 12). but my aim is to keep those inputs and remove others. and when i try to reverse the code as below it removes all the inputs. if ($(this).parent("td").attr("class") != i && $(this).val() == thisvalue) { $(this).remove(); } please guide me. thanks in advance.
  3. funbinod

    MYSQLI REPLACE() function while inserting multiple rows

    wow! this solved the problem. i checked for all the tables and found some columns be empty that led to this problem. i corrected them and found that the above code is working properly. thank u for the idea.
  4. funbinod

    MYSQLI REPLACE() function while inserting multiple rows

    thank u for the reply. and sorry for the undefined table screenshots. here i'm again posting the screenshot with some markings. my purpose of this practice is to change the underlined part of the data before copying and the calculation (math) is for that purpose. i'm copying the bordered 4 rows and the math should be applied for all the rows. but it inserted all the rows but only one row with data and rest NULL. and one more thing. i tried to shorten the code and found some interesting results. the following code inserted all the rows with data INSERT INTO projectra (projid, nermid, name, code, per, unitper, description, materials, manerials, macerials) SELECT '$projid', fullid, name, code, per, unitper, description, REPLACE (materials, SUBSTRING_INDEX(materials, ';', -1), ( (SELECT (lurate) FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) ) ), REPLACE (manerials, SUBSTRING_INDEX(manerials, ';', -1), '0'), REPLACE (macerials, SUBSTRING_INDEX(macerials, ';', -1), '0') FROM nerms WHERE fullid='$nid'"); and the following code inserted 2 rows with data and 2 rows NULL INSERT INTO projectra (projid, nermid, name, code, per, unitper, description, materials, manerials, macerials) SELECT '$projid', fullid, name, code, per, unitper, description, REPLACE (materials, SUBSTRING_INDEX(materials, ';', -1), ( (SELECT (lurate) FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) + ( (SELECT uweight FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) * (SELECT rate FROM transport WHERE name=(CONCAT((SELECT ctype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)), '-BLACK TOPPED')) AND cid='$cid' AND active='Y') * (SELECT SUBSTRING_INDEX((SELECT IF ((SELECT itype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1))='L', Ldistance, Fdistance) FROM projects WHERE fullid='$projid'), ';', 1)) ) ) ), REPLACE (manerials, SUBSTRING_INDEX(manerials, ';', -1), '0'), REPLACE (macerials, SUBSTRING_INDEX(macerials, ';', -1), '0') FROM nerms WHERE fullid='$nid'"); the second part of the addition could be any one among the three on the main code. thank u again.
  5. funbinod

    MYSQLI REPLACE() function while inserting multiple rows

    thank u for the reply. but if my explanation above was unclear i again explain - columns with data also converts to NULL except one row. you can check those two screenshots.
  6. i was trying to insert rows from one table to another and edit values before inserting. for that i did the following INSERT INTO projectra (projid, nermid, name, code, per, unitper, description, materials, manerials, macerials) SELECT '$projid', fullid, name, code, per, unitper, description, REPLACE (materials, SUBSTRING_INDEX(materials, ';', -1), ( (SELECT (lurate) FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) + ( (SELECT uweight FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) * (SELECT rate FROM transport WHERE name=(CONCAT((SELECT ctype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)), '-BLACK TOPPED')) AND cid='$cid' AND active='Y') * (SELECT SUBSTRING_INDEX((SELECT IF ((SELECT itype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1))='L', Ldistance, Fdistance) FROM projects WHERE fullid='$projid'), ';', 1)) ) + ( (SELECT uweight FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) * (SELECT rate FROM transport WHERE name=(CONCAT((SELECT ctype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)), '-GRAVELL')) AND cid='$cid' AND active='Y') * (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX((SELECT IF ((SELECT itype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1))='L', Ldistance, Fdistance) FROM projects WHERE fullid='$projid'), ';', 2), ';', -1)) ) + ( (SELECT uweight FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)) * (SELECT rate FROM transport WHERE name=(CONCAT((SELECT ctype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1)), '-EARTHEN')) AND cid='$cid' AND active='Y') * (SELECT SUBSTRING_INDEX((SELECT IF ((SELECT itype FROM items WHERE fullid=SUBSTRING_INDEX(materials, ';', 1))='L', Ldistance, Fdistance) FROM projects WHERE fullid='$projid'), ';', -1)) ) ) ), REPLACE (manerials, SUBSTRING_INDEX(manerials, ';', -1), '0'), REPLACE (macerials, SUBSTRING_INDEX(macerials, ';', -1), '0') FROM nerms WHERE fullid='$nid'"); this works very good - calculates and replaces the exact point as expected. but the problem is it calculates only one random row and lefts other to be NULL. for example, if there are 4 rows that meet the condition, all the 4 rows are copied but only one row contain the expected data and others are left to be NULL. i've submitted 2 screenshots of phpmyadmin showing 2 tables - first one is from which i am coping data (there you can see data on cells) and another is of next table after the copying data (there you can see NULL on cells). thanks in advance...
  7. funbinod

    insert csv into mysql problem

    PHP error is enabled. and there is nothing added on error log of my cpanel. the only thing happens when i post the csv file is - "Aw, Snap" page. its so much confusing. it works very fine when i use LOAD DATA method.
  8. funbinod

    insert csv into mysql problem

    i've posted the screenshot. it just displays "Aq, Snap!" DEV TOOLS also disconnects. and yes! the file upload is done through jQuery ajax. when i check manually, the file uploads but the mysql inserting part is not executed. and i found some mistakes on my code. i corrected it as following. but it still is not performing the action. $q = $mysqli->prepare("INSERT INTO projects (name, ctrtype, budhead, code, wardno, govallo, startdate, enddate, fy, cid, uid) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); if (!$q) { echo "<div id='success'>NO</div>"; echo "<div id='msg'>Error: $mysqli->error</div>"; } else { $q->bind_param("siisidssiii", $prjname, $ctrtype, $data[2], $data[3], $data[4], $data[5], $data[6], $data[7], $ay, $cid, $uid); if (!$q->execute()) { echo "<div id='success'>NO</div>"; echo "<div id='msg'>Error: $q->error</div>"; } else { echo "<div id='success'>YES</div>"; echo "<div id='msg'>SUCCESSFULLY INSERTED DATA IN FILE!</div>"; $_SESSION["msg"] = "SUCCESSFULLY INSERTED DATA IN FILE!"; } }
  9. funbinod

    insert csv into mysql problem

    because i want to filter data supplied in the csv file.
  10. funbinod

    insert csv into mysql problem

    hello all! i am trying to upload and insert data on a csv file to mysql. it uploads but could not insert data to mysql. following is the work i've done. $handle = fopen($targetpath, 'r'); $firstline = true; while (($data = fgetcsv($handle, 5000, ',')) !== FALSE) { if (!$firstline) { $continue = true; if ($data[0] == "" && $data[1] == "" && $data[2] == "" && $data[3] == "" && $data[4] == "" && $data[5] == "" && $data[6] == "" && $data[7] == ""){ $continue = false; } if (strlen($data[0]) != strlen(utf8_decode($data[0]))) { $prjname = ($data[0]); } else { $prjname = strtoupper($data[0]); } if ($data[1] == "CONTRACTOR") { $ctrtype = 1; } else if ($data[1] == "USER COMMITTEE") { $ctrtype = 2; } else { $continue = false; } if (!is_numeric($data[2])) { $continue = false; } if ($continue == true) { $q = $mysqli->query("INSERT INTO projects (subdate, name, ctrtype, budhead, code, wardno, govallo, startdate, enddate, fy, cid, uid) VALUES ('$subdate', '$prjname', '$ctrtype', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$ay', '$cid', '$uid')"); if (!$q) { echo "<div id='success'>NO</div>"; echo "<div id='msg'>Error: $mysqli->error</div>"; } else { $q->bind_param("siisidssiii", $subdate, $prjname, $ctrtype, $data[2], $data[3], $data[4], $data[5], $data[6], $data[7], $ay, $cid, $uid); if (!$q->execute()) { echo "<div id='success'>NO</div>"; echo "<div id='msg'>Error: $q->error</div>"; } else { echo "<div id='success'>YES</div>"; echo "<div id='msg'>SUCCESSFULLY INSERTED DATA IN FILE!</div>"; $_SESSION["msg"] = "SUCCESSFULLY INSERTED DATA IN FILE!"; } } } } $firstline = false; } unlink($path); can u please guide where i did mistake??? thank u in advance..
  11. funbinod

    setting page break

    tr:nth-child(4n) {page-break-after: always;} this didnot work as expected
  12. funbinod

    setting page break

    hello all! i was trying to set page break while printing my html page after every 4 table rows. can anyone guide me??? thanks in advance.
  13. funbinod

    finding elements with data- attributes

    i solved the problem using ".attr('itype', itype)" instead of using .data(). but is it ok to use non-standard attributes?
  14. funbinod

    finding elements with data- attributes

    thank u for the reply. but i didnot what you asked to check in the developer tools. i've checked in my own way if it adds a data attribute to the span or not. i had mentioned this above also. i checked it in two ways. after adding the data-itype i tried to count the span number with data-itype='F' alert($(".regmattable").find("span[class='matcosts'][data-itype='F']").length); it alerts 0 (zero). but when i check if there is data-itype set alert($(".regmattable").find("span[class='matcosts']").data("itype")); it alerts 'F', as i've set earlier. this means data-itype is set with the given value to the selected span, but i could not find the span with the data attribute.
  15. hello experts! i mate a problem while trying to find elements with dynamically set data attribute. first i set data attribute like this ... $("span[class='matcosts']").data("itype", "F"); second i try to find it ... $(".regmattable").on("keyup", ".matcount", function(e) { alert($(".regmattable").find("span[class='matcosts'][data-itype='F']").length); // both 'matcount' and 'matclass' are insite 'regmattable' }) this above code alerts 0 (zero). but when i try to find the data from the 'matcosts' span (as below), it gives 'F' (as i passed it before). alert($(".regmattable").find("span[class='matcosts']").data("itype"); can u tell me where did i make mistake? and please can u guide me how can i achieve this???? thank you in advance.
×