I am trying to push to the javascript array after looping 200 times through the member array to push every member that matches the department selected description into the javascript array., However it fails
If I understand correctly, I'd probably use a foreach() loop:
PHP Code:
<script type='text/javascript'> <?php foreach($members as $memb) { if ($memb['department'] == $depttts){ echo 'contacts.push({"NAME":"SirSaula","TITLE":"John","CONTACT":"bab","RESEARCH":"Ph.D."});'; // possible a "break;" here if you want to terminate loop once a match is found? } } ?> </script>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Your method worked now the final thing instead of strings i wish to push the entire php array contents into the javascript array
My attempt is below but it did not work.
PHP Code:
<?php foreach($members as $memb) { if ($memb['department'] == $depttts){ echo 'contacts.push({"NAME":<?php echo json_encode($memb[i]['firstname']); ?>,"TITLE":<?php echo json_encode($memb[i]['title']); ?>,"CONTACT":<?php echo json_encode($memb[i]['email']); ?>,"RESEARCH":"Ph.D."});'; // possible a "break;" here if you want to terminate loop once a match is found? } } ?>
Originally Posted by NogDog
If I understand correctly, I'd probably use a foreach() loop:
PHP Code:
<script type='text/javascript'> <?php foreach($members as $memb) { if ($memb['department'] == $depttts){ echo 'contacts.push({"NAME":"SirSaula","TITLE":"John","CONTACT":"bab","RESEARCH":"Ph.D."});'; // possible a "break;" here if you want to terminate loop once a match is found? } } ?> </script>
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks