Jump to content

funbinod

Members
  • Posts

    501
  • Joined

  • Last visited

Posts posted by funbinod

  1. 7 hours ago, justsomeguy said:

    If you look for just elements with span[class='matcosts'] or [data-itype='F'], does it find those?  Is it just an issue with the selector?  It would be interesting to look at the DOM in the developer tools when you run that to inspect that element and see if it actually adds a data attribute to it.

    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.

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

  3. 11 hours ago, Ingolme said:

    Is there a reason why you can't move those lines of code inside the success function?

    i don't know! i was just wondering for this.

    thank u for the reply. and i think i need to move those lines inside the success function.

    i wish some more guidance here. will u please help me??

    from the ajax request, i get current latitude and longitude data from my gps tracker device. and to place a marker to the map i send those data to another page like below and load that page to a div in the current page.

    success: function(res) {
    	var lat = res[imei].lat;
    	var lng = res[imei].lng;
    	if (loaded == "NO") {
    		var loadmapurl = "gps.php?lat=" + lat + "&lng=" + lng;
    		$("#loadmap").load(loadmapurl);
    		loaded == "YES";
    	} else {
    		var latlng = new google.maps.LatLng(lat, lng);
    		marker.setPosition(latlng);
    	}
    }
    setTimeout(executeQuery, 5000);

    this ajax request is loaded every 5000ms.

    for each ajax success function, i check if the map page is loaded already or not. and if the page is loaded already loaded i wish not to load the page anymore but to move the marker according the current latitude and longitude value. the marker variable inside the else block is from the loaded page (i.e.: "gps.php?........").

    is the above try good to perform my requirement? is the above try to load a map is good enough? or i've to try something else to load a map?

     

    (NOTE: i cannot say what happens with this current code because there is a header setting error (i.e.: access-control-allow-origin header not present......) on my gps service provider api link.)

     

    thank you in advance.

  4. i was trying to use a ajax returned value out of the ajax function but it didn't work. can anyone please guide me. here is the code i tried.

    		var lat, lng;
    		$.ajax({
    			url: url,
    			dataType: "json",
    			method: "get",
    			success: function(res) {
    				var lat = res[imei].lat;
    				var lng = res[imei].lng;
    			}
    		});
    		$("#lng").text(lng);
    		$("#lat").text(lat);

    thanks in advance.

  5. very good suggestion. i didnot know about data attribute in html 5 and jquery. your guidance made me clear almost all about data- attribute.

    but one thing more. i got confused using selector for this attribute.

    shall i have to use, in jquery

    $("input[data-class='resultdate'"]

    or there is something special method for this?

     

    thank u.

  6. hello all!

    i've a autocomplete field which has a class attribute 'resultdate'. and i want to select that element using its class attribute. but when i try to catch that field i found that the autocomplete specified class is also added to it.

    	$(function() {
    		$('.resultdate').autocomplete({     ////// this is an input field and i've many input fields with different class names.
    			source: "selectdate.php",
    			minLength: 0,
    			autoFocus: false,
    			select: function(e) {
    				$(this).val($(this).substr(0,10));
    			}
    		}).focus(function(){
    			$(this).autocomplete("search");
    		})
    	});
    
    	$('#editmain input').on('keypress', function(e) {
    		if (e.which === 13) {
    			e.preventDefault();
    			$("#msg").empty().hide();
    			var thisid = $(this).attr("termid");
    			var col = $(this).attr("class");     // i use the class to identify the field and update it through ajax request
    			alert(col);
    			var newvalue = $(this).val();
    			editterm(thisid, col, newvalue);
    		}
    	})

    for other plain input field (means the inputs that donot have any autocomplete function) it works fine. but for autocomplete field (for example class='resultdate') this gives 'resultdate ui-autocomplete-input' as its class

    please guide how can i select the only class that i,ve specified?

     

    thank u in advance..

  7. hello all,

    i am trying to run an ajax request inside a for loop. and when the response is true, i want to run another ajax only once. but the second ajax also runs multiple times.

    here is the code i tried ....

    					var i;
    					for (i=0; i< feeid.length; i++) {
    						$.ajax({
    							url: "submitnewjournal.php",
    							method: "POST",
    							data: {
    								m: m,
    								fullvn: fullvn,
    								vn: vn,
    							},
    						})
    						.done (function(result) {
    							var success = $(result).filter("#success").text();
    							$("#msg").text($(result).filter("#msg").text());
    							if (success == "NO") {
    								$('#pwait').hide('clip', "fast");
    								$("#msg").css("color", "red").show("bounce", 100);
    								$('#feelist, #studentlist').show('fade', 250);
    							} else {
    								$("#msg").css("color", "green").show("bounce", 100);
    								$("#fullvn").text($(result).filter("#newfullvn").text());
    								$("#prefix").text($(result).filter("#newprefix").text());
    								$("#vn").text($(result).filter("#newvn").text());
    /***********************************************************************************************/
    /************************* this is the part i want to run onle one time*************************/
    /***********************************************************************************************/
    								if (sendnotice == "Y") {
    									$("#msg").text("Invoice saved successfully. Now sending notification!");
    									var target = "< PARENTS >";
    									var receipients = "INVOICE";
    									var clas = $('#clas :selected').val();
    									var sec = $('#sec').val();
    									$.ajax({
    										url: "noticeprocess.php",
    										method: "POST",
    										data: {
    											target: target,
    											targetid: target,
    											receipient: receipients,
    											token : receipients
    										}
    									})
    									.done(function(result) {
    										$("#msg").hide("fade", 100).empty().text($(result).filter("#msg").text());
    										var success = $(result).filter("#success").text();
    										if (success == "YES") {
    											$("#msg").css("color", "green").show("bounce", 100);
    											$("#pwait").hide("clip", "fast");
    //											$('#mainarea').load('mnthsalary.php');
    										} else if (success == "NO") {
    											$("#msg").css("color", "red").show("bounce", 100);
    										}
    									})
    									.fail(function(e) {
    										$("#msg").hide("fade", 100).empty().text("Connection Error!").css("color", "red").show("bounce", 100);
    									})
    									window.open("print.php?m=newmnthinvoice&invno=" + fullvn, "_new");
           /*********************************************************/
    								} else {
    									$("#msg").text("Invoice saved successfully.");
    									$('#pwait').hide('clip', "fast");
    								}
    							}
    						})
    						.fail(function() {
    							$('#pwait').hide('clip', "fast");
    							$('#msg').text('Connection problem!').css('color', 'red');
    							$('#feelist, #studentlist').show('fade', 250);
    						})
    					}

     

    please guide me how can i achieve this.

     

    thank u in advance....

  8. <!-- first of all completely sorry if this is not the right forum to ask this. but i've no idea which is the right forum for this --->

    hello all!

    i was learning how to use back4app parse on my website. while going through documentation on parseplatform.org, i found a sample block as below..

    curl -X POST \
      -H "X-Parse-Application-Id: APPLICATION_ID" \
      -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
      -H "X-Parse-Revocable-Session: 1" \
      -H "Content-Type: application/json" \
      -d '{"username":"cooldude6","password":"p_n7!-e8","phone":"415-392-0202"}' \
      https://parseapi.back4app.com/parse/users

    but i could not understand how to implement this on my php code.

    this might be because i am completely unfamiliar to curl.

    UPDATE: while searching the web for more about uses of curl, i found something else that doesn't match the above format given by parseplatform.org. this blew my head more.

    please someone help me understand all these things.

  9. hello all!

    i'm new to java and android studio.

    i was trying to check and create new file and do something in it.

                        if (!file1.exists()) {
                            try {
                                file1.createNewFile();
                                Toast.makeText(StartActivity.this, "key file created!" + directory, Toast.LENGTH_LONG).show();
                                Intent intent = new Intent(StartActivity.this, KeyActivity.class);
                                startActivity(intent);
                                StartActivity.this.finish();
                            } catch (IOException e) {
                                e.printStackTrace();
                                Toast.makeText(StartActivity.this, "key file creation failed!" + directory + "--" + e, Toast.LENGTH_LONG).show();
                            }
                        } else {
                            StringBuilder keyData = new StringBuilder("");
                            try {
                                FileInputStream kfile = openFileInput(keyfile);
                                InputStreamReader kSr = new InputStreamReader(kfile);
                                BufferedReader bufferedReader1 = new BufferedReader((kSr));
                                String readKey = bufferedReader1.readLine();
                                if (readKey != null) {
                                    keyData.append(readKey);
                                    final String key = keyData.toString();
                                    Toast.makeText(StartActivity.this, "found login id and key on " + directory + "! Checking the credentials!", Toast.LENGTH_LONG).show();
                                    new AsyncLogin1().execute(loginId, key);
                                } else {
                                    Intent intent = new Intent(StartActivity.this, KeyActivity.class);
                                    intent.putExtra("loginID", loginId);
                                    startActivity(intent);
                                    StartActivity.this.finish();
                                }
                                kSr.close();
                            } catch (IOException ioe1) {
                                ioe1.printStackTrace();
                                Toast.makeText(StartActivity.this, "error: " + ioe1, Toast.LENGTH_LONG).show();  // this is the part that is displayed as error
                            }

    i tried all these and got unexpected error!

    while running this, it goes inside the file existence block and returns the IOException error saying "No such file or directory". Please someone guide me where i made mistake.

    EDIT:

    this is the file path:

    File thisdirectory = this.getFilesDir();
    File directory = new File(thisdirectory + "/online/is_cool_staffs/");
    if (!directory.exists()) {
      directory.mkdirs();
    }
    File file1 = new File(directory + keyfile);
    

     

    thank you in advance...

  10. /////////// this is a part of the second query /////////////
    			SELECT SUM(debit) debit, SUM(credit) credit FROM (
    				SELECT NULL ob, SUM(debit) debit, SUM(credit) credit FROM journal WHERE aid='$aid' AND cid='$cid' AND ay='$ay'
    				UNION
    				SELECT NULL ob, SUM(fee) debit, NULL credit FROM invoice WHERE stuid='$aid' AND cid='$cid' AND ay='$ay'
    				UNION
    				.............
    				.............
    				.............
    			) as balance
    
    /////////// in this second query i use $aid from the previous one...
    2 hours ago, Ingolme said:

    Does your second query make use of data from the first query?

    yes.the second query searches data from multiple tables and calculate them according to the data derived from first prepared statement.

  11. hello all!

    i was trying to run another query inside a while loop of a prepared statement.

    	$qs = $_POST['queryString']."%";
    	$ledq = $mysqli->prepare("SELECT name, fullid aid, ob FROM account WHERE cid='$cid' AND name LIKE ? AND ac_id IN ('$q') ORDER BY name LIMIT 20");
    	if (!$ledq) {
    		echo "Error: " . $mysqli->error;
    	} else {
    		$ledq->bind_param('s', $qs);
    		$ledq->execute();
    		$ledq->bind_result($name, $aid, $ob);
    		$ledq->store_result();
    		while ($ledq->fetch()) {
    			$balq = $mysqli->query("SELECT SUM(debit) debit, SUM(credit) credit FROM ..................");
    			...............
    			...............
    			...............
    		}
    		$ledq->free_result();
    		$mysqli->close();
    	}

    when i use free result outside the while loop it gives out of sync error. if i use free result inside the while loop and before the next query, it returns only one row.

    i also tried more_result before executing the next query. but it only worked while testing locally. when i upload it to my server and try, it gives nothing.

    please someone guide me what is the best solution!

     

    thank you in advance..

  12. 4 hours ago, Ingolme said:

    Where did you use the max() function?

    ...........
    ...........
    for ($i = 0; $i < $highmq->num_rows; $i++) {
      ..........
      ..........
      ..........
      $highmarks[] = ($highmarkth + $highmarkpr);
    }
    $highmark = implode(',', $highmarks);
    echo max($highmark);

    here!

  13. 9 hours ago, justsomeguy said:

    Your code is kind of inconsistent.  This looks problematic:

    For example, you don't define those 2 variables outside of those if statements, so they will only be defined if either of those if statements match.  Then, you set one of them to an array with explode, and the other variable to a number.  Then you try to add an array and number.  What do you think that's going to do, when you add an array and a number?  In fact, what do you expect to happen when you use the + on an array at all?  The data type of those variables isn't consistent, if it goes in the first if statement then $highmarkth will be an array, but if it goes in the second one then it will be a number.  So after those 2 if statements either of those variables could be either an array or a number, or they could both be undefined.  Then you try to add them.  Also, if it goes in the second if statement then both variables get set, so that will overwrite anything you did in the first if statement.  So if markpractical is not empty then those 2 variables get set right there regardless of what marktheory is set to.  If both marktheory and markpractical are set then the values that were set in the first if block will get overwritten by the second block.

    thank you @justsomeguy for the reply. your reply helped me to understand some new things. it is fruitful.

    i want to explain some more about my mysql columns. in the table marksheet, i insert data to only one column at one time. this means in each row, if it has data on marktheory then markpractical is surely empty. and if markpractical has some data in it, then marktheory is surely blank. so now do you think it would be ok if i set $highmarkth and $highmarkpr outside the if statements and set $higmark as an array outside the for loop?

     

    9 hours ago, Ingolme said:

    It seems that in some cases, the variable is being passed over from the previous loop iteration because one of the fields is an empty string and you're not initializing it inside the loop. You also are initializing $highmarkth as an array but the converting it to a number.

    Perhaps this may suit your requirements better:

    
    $highmark = [];
    for ($i = 0; $i < $highmq->num_rows; $i++) {
      $rows = $highmq->fetch_assoc();
    
      // Initialize theory and practical marks
      $highmarkpr = 0;
      $highmarkth = 0;
      
      $data = explode("#", $rows['marktheory']);
      if(isset($data[2])) {
        $highmarkth = (float) $data[2];
      }
    
      $data = explode("#", $rows['markpractical']);
      if(isset($data[2])) {
        $highmarkpr = (float) $data[2];
      }
    
      // Sum the two and add the result to the list of high marks
      $highmark[] = $highmarkth + $highmarkpr;
    }
    
    echo implode(',', $highmark);

    For security you should be using prepared statements if you have variables in the query.

    and thank you too @Ingolme . your suggested code guided me very nicely. it gave the data with commas in it. but one problem more occurred. when i use max() function, it says it is not an array (Warning: max(): When only one parameter is given, it must be an array in J:\xampp\htdocs\is-cool\test.php on line 23). and i used just mysqli->query in stead of prepared statement because it is executed internally. it has no user submitted data. wouldn't it be ok?

  14. 4 minutes ago, Ingolme said:

    Can you provide an example of what is in the marktheory and markpractical fields?

    they are varchar field and contain 3 types of data on them. the datas are saperated by a hash (#) key. for example "ET001#10#74.5". From this i explode the value and get the last offset for calculation

     

    thank you

  15. 7 hours ago, Ingolme said:

    Where did that string come from? Information has been lost and is irrecoverable, you have to get the missing information from the original source that created the string.

    the all i did is the same what i've kept in my question above.

    i'm putting the code again here.

    from the query i get values from columns "marktheory" and "markpractical", then calculate them and try to get highest value. in the mentioned code, i expect the values to be in array in "$highmark". when i echo it, i get the value altogether without commas (as i explained above).

    $cid = 2;
    $subid = 10;
    $clas = 'PG';
    $highmq = $mysqli->query("SELECT marktheory, markpractical FROM marksheet WHERE studentid IN (SELECT fullid FROM students WHERE class='$clas' AND cid='$cid') AND (marktheory LIKE '%#$subid#%' OR markpractical LIKE '%#$subid#%') AND cid='$cid'");
    $highmarkth = array();
    for ($i = 0; $i < $highmq->num_rows; $i++) {
    	$rows = $highmq->fetch_assoc();
    	if ($rows['marktheory'] != "") {
    		$highmarkth = explode("#", $rows['marktheory'])[2];
    		$highmarkpr = 0;
    	}
    	if ($rows['markpractical'] != "") {
    		$highmarkpr = explode("#", $rows['markpractical'])[2];
    		$highmarkth = 0;
    	}
    	$highmark = ($highmarkth + $highmarkpr);
    	echo max($highmark); /////////// gives error as the $highmark is not an array
        echo $highmark //////////////// gives "7474.776.89578.3" /////// i wish this to b as "74,74.7,76.8,95,78.3"
      }

     

    thank you.

  16. thank u @Ingolme for the reply!

    the exactly is my problem. the result i want is derived as string not as an array. as i mentioned above the result i got "7474.776.89578.3" contains FIVE values "74, 74.7, 76.8, 95, 78.3". i wish them as array. and then, i think, the "max()" function will do the rest.

  17. hello all!

    i was trying to get max value from a mysql query derived values

    but i could not succeed. please guide what i made mistake.

     

    below is the code i tried. in this after fetching data from mysql table, i made some calculations and derived data like this

    ////////////////// 7474.776.89578.3 //////////////////////////

    which actually contains 5 values ( 74,74.7,76.8,95,78.3 )

    what i want is to select the number 95.

    what is the proper method?

    thank u in advance.

    $cid = 2;
    $subid = 10;
    $clas = 'PG';
    $highmq = $mysqli->query("SELECT marktheory, markpractical FROM marksheet WHERE studentid IN (SELECT fullid FROM students WHERE class='$clas' AND cid='$cid') AND (marktheory LIKE '%#$subid#%' OR markpractical LIKE '%#$subid#%') AND cid='$cid'");
    $highmarkth = array();
    for ($i = 0; $i < $highmq->num_rows; $i++) {
    	$rows = $highmq->fetch_assoc();
    	if ($rows['marktheory'] != "") {
    		$highmarkth = explode("#", $rows['marktheory'])[2];
    		$highmarkpr = 0;
    	}
    	if ($rows['markpractical'] != "") {
    		$highmarkpr = explode("#", $rows['markpractical'])[2];
    		$highmarkth = 0;
    	}
    	$highmark = ($highmarkth + $highmarkpr);
    	echo max($highmark);
      }

     

  18. ok! i solved this like this

    	if ($sec == 'ALL') {
    		$stmt = $mysqli->prepare("SELECT CONCAT(fname, ' ', lname) AS name, fullid, roll, section FROM students WHERE class=? AND ay='$ay' AND cid='$cid'");
    		$stmt->bind_param('s', $clas);
    	} else {
    		$stmt = $mysqli->prepare("SELECT CONCAT(fname, ' ', lname) AS name, fullid, roll, section FROM students WHERE class=? AND section=? AND ay='$ay' AND cid='$cid'");
    		$stmt->bind_param('ss', $clas, $sec);
    	}

    thank u for being with me and giving some hint!

    is there any other good idea to do this?

  19. @Ingolme thank u for the reply! i appreciate your suggestion. but my requirement is something different. i have multiple cases for passing variables to the prepared statement.

    value for $wh and $param differ if the case is different.

    like - in the above example the value of $wh and $param are set when $sec has different value. but if $sec is not set differently then $wh and $param will have only one parameter.

    	if ($sec == 'ALL') {
    		$wh = 'class=?';
    		$param = "'s', $clas";
    	} else {
    		$wh = "class=? AND section=?";
    		$param = "'ss', $clas, $sec";
    	}

    how can i solve this issue then?

  20. hello all! greetings!

    i'm trying to fetch data from a prepared statement and using some variables to pass the query

            $wh = "class=? AND section=?";
            $param = "'ss', $clas, $sec";
            $stmt = $mysqli->prepare("SELECT CONCAT(fname, ' ', lname) AS name, fullid, roll FROM students WHERE $wh AND ay='$ay' AND cid='$cid'");
    	if (!$stmt->bind_param($param)) {
    		echo "Bind Error: " . $stmt->error;
    	}
    	?>

    this is showing error but only "Bind Error:" not the "$stmt->error". i tried to echo $wh and $param value also and they give the same value as i intend. why this is happening?

    please guide.

    thanks in advance.

×
×
  • Create New...