0

I have situation where I want to output two table columns from my query in array. Ideally I would like to output one ID_1 then second ID_2 and after I store all ID's in array I want to loop through that array to check if ID_1 is greater than 0 and if it is I would like to use matching ID_2 to hide element. Here is my code that i have so far:

var records = [];

~[tlist_sql;
  SELECT ID_1, ID_2 
  FROM SLOTS
  ]
 records.push("~(ID_1)","~(ID_2)");
[/tlist_sql]

for(var i=0; i< records.length; i++){
    //if ID_2 is greater than 0 
    if(records[i].idTwo > 0){
        var test = ('#row_' + records[i].idOne).val();  
                alert(test)
        //here I want to use ID_1 to hide row 
        $j('#row_' + records[i].idOne).parent('.hideElement').hide();
        $j('#button1').hide();
    }       
}

Here is how my array records looks like:

[-1,2050,-1,2046,15,2048,0,2044,10,2051,0,2047]

So as you can see in this array only two records will pass if statement where ID_1 is 15,10 and ID_2 is 2048,2051. My current code doesn't use correct values looks like id's are split some how. Does anyone know how I should look for ID_1 and then for ID_2 and is array the best to use in this case? Thank you.

8
  • Can you post what you expect the array to look like? Commented Feb 25, 2016 at 19:38
  • 2
    line 1 of your code creates an array. Commented Feb 25, 2016 at 19:38
  • I want my array to look how it is but my problem is how to loop and get ID_2 inside of my if statement. Commented Feb 25, 2016 at 19:39
  • So in the array you've posted, we are looking at [ID_1, ID_2, ID_1, ID_2]? Commented Feb 25, 2016 at 19:40
  • 1
    That is special code that powerschool use to output values from the query. Commented Feb 25, 2016 at 19:51

2 Answers 2

2

Something like this perhaps:

var records = [];

~[tlist_sql;
SELECT ID_1, ID_2 
FROM SLOTS
]

records.push({
   'idOne' : "~(ID_1)",
   'idTwo' : "~(ID_2)"
});
[/tlist_sql]

Then when accessing these records:

for(var i=0; i< records.length; i++){
    //if ID_1 is greater than 0 
    if(records[i].idOne > 0){
        //here I want to use ID_2 to hide row that has matching ID
        $j('#row_' + records[i].idTwo).parent('.hideElement').hide();
        $j('#button1').hide();
    }       
}
Sign up to request clarification or add additional context in comments.

8 Comments

Shoot! You got to it first. I do like encapsulating related data in objects.
I do not why but this line of the code: $j('#row_' + records[i].idTwo) if I try to do .val() and alert gives me values 'on','on'. Do you know what can cause that output?
Could you update your main question with the code you have now where you are doing an alert on the value. As well the HTML of #row would be helpful just to get a better idea of what you mean.
I did update my question. Line of code where I use JQuery selector to get row_ID and hide parent does not work. I'm not sure if something is wrong with my JQuery or values that I'm passing in.
In your updated code you have idOne where idTwo should be and vice versa. According to your description you wanted to check if idOne was > 0 and then use idTwo to match and hide an element. Not sure if that solves your issue though.
|
1

Create an object:

var records = [];

~[tlist_sql;
  SELECT ID_1, ID_2 
  FROM SLOTS
  ]
 records.push({id1:":~(ID_1)",id2:"~(ID_2)"});
[/tlist_sql]

for(var i=0; i< records.length; i++){
    //if ID_1 is greater than 0 
    if(records[i].id1 > 0){
        //here I want to use ID_2 to hide row that has matching ID
        $j('#row_' + records[i].id2).parent('.hideElement').hide();
        $j('#button1').hide();
    }       
}

https://jsfiddle.net/78s3uL95/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.