Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6694473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:06:21+00:00 2026-05-26T06:06:21+00:00

I am wanting to create a PHP loop to get all of the ids

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:06:21+00:00Added an answer on May 26, 2026 at 6:06 am

    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.

    <!-- rest of page -->
    <script type="text/javascript">
    <?php
    
      // Get all the results from the DB
      $result = mysql_query("SELECT `div-id`, `content` FROM `table` WHERE `some_field` = 'some value'");
      // loop the db results
      while ($row = mysql_fecth_assoc($result)) echo "$('#{$row['div-id']}').append('{$row['content']}');\n";
    
    ?>
    </script>
    <!-- rest of page -->
    

    Should output something like:

    <!-- rest of page -->
    <script type="text/javascript">
      $('#div-id1').append('HELLO CONTENT1');
      $('#div-id2').append('HELLO CONTENT2');
      $('#div-id3').append('HELLO CONTENT3');
    </script>
    <!-- rest of page -->
    

    …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 $result in PHP and create one large array, then json_encode() it and loop it in JS. Your choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wanting to create a VB.Net app that checks a database and then
I'm wanting to detect all objects(classes) defined in a php file (example: flavors.php). The
Goal: I want to get the text from the selected element and then create
I am wanting to create a program that talks with a Cometd server to
I've been wanting to create a HUD style loading bar like the SMS app
This situation arises from someone wanting to create their own pages in their web
What I am wanting to do is create a PDF ideally from HTML code.
i am wanting to create an open id login, i am wondering if i
I have a client who is wanting to create a link which contains product
I have inherited a PHP project and the client is wanting to add some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.