1

My problem is that the database fields have been badly designed by previous people before me. We are accessing the table rows horizontally.

I am working with PHP and jQuery right now and I am passing data back and forth through AJAX. In PHP I am accessing this array like so:

$attendance['date_lesson_' . $lessonCount] 

where lessonCount is a number from 1-10 that is incremented i.e. if lessonCount = 1 then above would be $attendance['date_lesson_1']

I am passing the attendance array through json_encode

How do I therefore access this field data_lesson_ 1 up to 10 in jQuery?

I am trying to do:

var lessonCount = 1;

attendance[i].date_lesson_+lessonCount

//do some stuff with attendance.date_lesson_ 
lessonCount++;

It was easy in PHP cause you concatenate strings with the dot "." but this isn't a string I'm dealing with in jQuery/JavaScript so how on earth would I do this?

Yes, I know. This is awkward. I agree 100%.

2 Answers 2

4

You’ll need to use bracket notation:

attendance['date_lesson_' + lessonCount]

Dot notation can only be used with identifier names as property names.

Sign up to request clarification or add additional context in comments.

Comments

0

Just a guess, I don't know how that json looks like.

attendance["date_lesson_"+lessonCount]

1 Comment

I refrained from showing the JSON because it's 50 fields long... (when it could have been 5)

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.