Jump to content

funbinod

Members
  • Content Count

    499
  • Joined

  • Last visited

Posts posted by funbinod


  1. On 9/24/2019 at 10:37 PM, justsomeguy said:

    It looks like you have a condition where you're trying to do everything real-time and getting messed up because you're changing things as you go.  Find the current selected row and save that as a variable.  Find the row to be selected and save that as a variable.  Then work with those variables instead of using CSS selectors to always find the things you're looking for in the data set that you're actively changing.

    Also, I assume you mean "keyup."

    thank you for the reply.

    i already tried to put the position of selected row using "index". but that also returned same problem.

     

    but now i solved the problem with a slight change on the above code. i just replaced ------------

    .data("selected", 'Y')

    to

    .attr("data-selected", 'Y')

     


  2. hello all

    i am trying to use 'keydown' function to move through html rows. but i could not succeed.

    here is what i tried--

    	$("body").on("keyup", function(e) {
    		if ($("#mid").find(".maintable tr[data-selected='Y']").length == 0) {
    			$("#mid").find(".maintable tr").first().data("selected", 'Y').addClass("thisrow");
    		} else {
    			if (e.which === 40) {
    				$("#mid").find(".maintable tr[data-selected='Y']").next().data("selected", 'Y').addClass("thisrow");
    				$("#mid").find(".maintable tr[data-selected='Y']").first().data("selected", 'N').removeClass("thisrow");
    			} else if (e.which === 38) {
    				$("#mid").find(".maintable tr[data-selected='Y']").prev().data("selected", 'Y').addClass("thisrow");
    				$("#mid").find(".maintable tr[data-selected='Y']").last().data("selected", 'N').removeClass("thisrow");
    			}
    		}
    	})

    in the above code, '#mid' is a div that holds data retrieved from jQuery.ajax function.

    below is the backend code data from which is attached to the '#mid' div.

    		$data = "<table class='maintable'>";
    		$sn = 0;
    		while ($r = $q->fetch_object()) {
    			$sn++;
    			$name = $r->name;
    			$aid = $r->aid;
    			$ac_id = $r->ac_id;
    			$ob = $r->ob;
    			$data .= "
    			<tr data-target='acregister.php?aid=$aid&m=e' data-selected='N'>
    				<td>$name</td>
    				<td style='width: 150px;'>$ac_id</td>
    				<td style='width: 150px;'>$ob</td>
    			</tr>";
    		}
    		$data .= "</table>";
    		
    		echo $data;

    here i want to use up and down arrows to move through the rows retrieved from ajax function. on the rows i've attached 'data-selected' value to know which row is selected. and on each keydown function i want change the 'data-selected' value of next row to 'Y' and change its value to 'N' for the previous one.

    the above code worked only once. it changed the value for new row but didnot change the value for the previous one and hence when i press down arrow, it selects first row but does not move to next row on another down arrow press.

    please guide me, what i missed?


  3. hello all!

    i'm trying something for binding parameters to a prepared statement like below.

    $tbl = 'stock';
    $cols = 'icode=?, item=?, catid=?, description=?, unitid=?, pprice=?, sprice=?, oqty=?, oprice=?, oamt=?, bcode=?';
    // $vals = "'101', 'ASUS H61M-E', 'abcde', '2', '1', '5300.00', '6500.00', '11', '5300', '55528', '101'";
    $vals = "101, ASUS H61M-E, abcde, 2, 1, 5300.00, 6500.00, 11, 5300, 55528, 101";
    $uq = $mysqli->prepare("UPDATE $tbl SET $cols WHERE $whcol='$whval'");
    if (!$uq) {
    	$msg = "Error1: $mysqli->error!";
    } else {
    	$uq->bind_param('sssssssssss', $vals);  // this doesn't work.
    //	$uq->bind_param('sssssssssss', 101, ASUS H61M-E, abcde, 2, 1, 5300.00, 6500.00, 11, 5300, 55528, 101); // but this works well.
    	if (!$uq->execute()) {
    		$msg = "Error3: $uq->error!"; ///// this says "No data supplied for parameters in prepared statement."
    	} else {
    		$msg = "UPDATED successfully!";
    	}
    }

    here i'm trying to put all the update values into a string and then bind it to the statement. but this says "No data supplied for parameters in prepared statement". but when i use individual values, it works fine. please suggest me something.

     

    thanks in advance.


  4. i found that what i learnt so far is also wrong.

    i corrected the aforementioned code like this

    $cuidstmt = $pgsql->prepare("SELECT cid, uid FROM user WHERE name=?");
    if(!$cuidstmt) {
    	echo "Error: " . $pgsql->errorInfo()[2];
    } else {
    	$cuidstmt->execute(array($u));
    	$cuidstmt->execute();
    	$cuidstmt->fetch();
    }

    but i still couldn't understand how can i get the result(s). where can i get the data from 'cid' and 'uid' columns mentioned in the prepared statement.

    thank u all in advance.


  5. hello all!

    i'm learning postgresql.

    i was just trying to fetch some data using prepared statement. but found that it is quiet different than mysql.

    the all i learnt searching on the web is this.

    $cuidstmt = $pgsql->prepare("SELECT cid, uid FROM user WHERE name=?");
    if(!$cuidstmt) {
    	echo "Error: " . $pgsql->errorInfo()[2];
    } else {
    	$cuidstmt->bindParam('i', $u);
    	$cuidstmt->execute();
    	$cuidstmt->fetch();
    }

    but i could not understand how can i print the required data. where the data is stored.

    just like in mysqli we can bind result on a string, how can i do that in pgsql?

    can u please help me?


  6. hello all.

    i was just wondering between these two versions of PHP - 5 & 7.

    right now i'm practicing on if PHP 5. and now i'm thinking of upgrading to PHP 7. and i want to know if my current code works with the new version or not. if i upgraded my PHP to 7, should i need to change all or some parts of the codes?

    thank you in advance.


  7. hello all!

    i was wandering through web to learn about audit trial. but could not find anything from where i can understand this clearly. can anyone please tell me in details about this???

    for nowm i want to know two things:

    1) is this automatically done by mysql as it's feature or this is my job to maintain the complete activity???

    2) if this is a mysql feature, is this available on all versions???

     

    thank you in advance...


  8. 17 hours ago, justsomeguy said:

    You need more unions to select each level of children if you want to do it all in SQL. 

    this hint solved my problem.

    i cheated the code like below.

    .......... AND projtype IN (SELECT id FROM projcat WHERE under=1 UNION SELECT id FROM projcat WHERE id=1 UNION SELECT id FROM projcat WHERE under IN (SELECT id FROM projcat WHERE under=1))

    thank u very very much...


  9. 15 hours ago, justsomeguy said:

    You need more unions to select each level of children if you want to do it all in SQL.  Obviously, you're limited to a maximum depth with that.  There are other ways to design tables and store paths where you could easily select all descendants or ancestors of a particular node.

    https://www.slideshare.net/billkarwin/models-for-hierarchical-data

    You're using the first example he gives.

    thank you for the reply.

    but it banged my head. this is beyond my practice and is very tough to understand. can't it be done with a simple modification to my code???? like........

    .......... AND projtype IN (1, SELECT id FROM projcat WHERE under=1 UNION SELECT id FROM projcat WHERE under IN (SELECT id FROM projcat WHERE under=1))

    thank u again.


  10. hello all!

    i am struggling with a problem in mysql.

    i want to select all rows from a table with an id and its child ids.

    i tried the following

    ............... AND projtype IN (SELECT id FROM projcat WHERE under=1 UNION SELECT id FROM projcat WHERE under IN (SELECT id FROM projcat WHERE under=1))

    it works. But this selects rows that matched the child ids only. i want to select all the rows which use the parent id also (i.e. '1' on the given example).

    please help me with some hints.

     

    thanks in advance....


  11. hi all! after long time i'm back here with a problem.

    i want to select all data attributes from a div with its name and value using jquery each function use that elsewhere.

    here is the html for the div.

    <div class='EW' data-rowid='1' data-unit='' data-workdesc='description' data-vby='2' data-distanceTot='50' data-AVcutTot='500' data-VcutTot='25000'></div>

    and i tested the following to get my result.

    		var datas = $(".EW").attributes;
    		$.each(datas, function(i,item) {
    			$("#msg").text(item.name + ":" + item.value);
    		})

    but i could not get any result. can u please guide me what is wrong? or suggest me any other best method to achieve this.

     

    thank you in advance.


  12. 4 hours ago, dsonesuk said:

    The only way to show or remove using == or != is to place those values in an array ShowRemoveArray=[3,6,9,12] (use current for loop to push these values into this array), then use jQuerys, $.inArray() to identify if  $(this).parent("td").attr("class") value that exists, is equal '==' array or not equal  '!=' to -1 (not found returned value)

    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();
    }

     


  13. 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.


  14. 5 hours ago, justsomeguy said:

    I read what you posted, but I don't know which columns are in that screenshot, there are no headers.  I don't know which tables they are either.  I don't know what values are in items, transport, projects, and nerms.

    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.

    1.jpg 2.jpg

    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.


  15. 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...

     

    1.jpg

    2.jpg


  16. On 7/20/2018 at 10:46 PM, justsomeguy said:

    If you're not seeing a PHP error message in the browser, then that's probably disabled.  Make sure you're using an error log and check the log to see the error message.

    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.


  17. 12 hours ago, justsomeguy said:

    What specifically happens when you run that?

    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!";
    								}
    							}

     

    screenshot.jpg


  18. 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..

×
×
  • Create New...