I am wanting to create a PHP loop to get all of the ids in a database table and them utilize them in an .append function. Basically what I want to happen is for every loop through the database, I want the jquery.append to run and change its #div labeling to be from the field div-id in the database
For example;
$('#div-id').append('HELLO CONTENT');
I know I can use an .each, but that doesn’t take care of the PHP part. I can do a while on the PHP, but that doesn’t take care of the Jquery part. Basically how I see it, they are creating their own loops and not working together.
You can do it in a
<script>tag output by the PHP page. I am assuming standard MySQL, should be fairly easy to adapt this to another database.Should output something like:
…so you’re doing the loop with PHP, and just outputting lines of JS, which will execute one after the other.
Alternatively, you could loop
$resultin PHP and create one large array, thenjson_encode()it and loop it in JS. Your choice.