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 9225483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:35:15+00:00 2026-06-18T04:35:15+00:00

I am working on an application where I fetch data from database and process

  • 0

I am working on an application where I fetch data from database and process it using javascript/jquery like this:

    $sqlEdit = "select revisionContent from tbl_revision where revisionId='".$_SESSION['contentId']."'";      //Query to fetch the result
    $rsEdit = $dbObj->tep_db_query($sqlEdit);
    $resEdit = $dbObj->getRecord($rsEdit);
    $IdLessContent = $resEdit['revisionContent']; 

 <script language="javascript">  
    var getSavedContent = '<?php echo json_encode($IdLessContent); ?>';
    var trimmedCont=($.trim(getSavedContent).slice(1));
    //console.log(trimmedCont);
    var lengthCont= trimmedCont.length;
    var trimmedCont=$.trim(trimmedCont.slice(0,lengthCont-1));
    console.log(trimmedCont);
    var test = $('<div class="addId">');
    test.append(trimmedCont);
    //console.log(test.html());
    test.children().each(function(index, value) {
         $(this).attr('id', "com-"+randomString());
     });
   //console.log(test.html());  
    viewContent  = test.html();

I get the required data in viewContent.I want to display it on the page in this section

        <div id="mainWrap" onClick="fnDestroyEditable();">
             <?php echo $resEdit['revisionContent']; ?>   //THis is the unprocessed data displayed directly from database.I want to display the processed data here
        </div> 

I know we cannot get javascript variables to PHP as both are different (one server side and other client). But then how can I achieve this in my scenario?
EDIT I would like to add that the returned data is HTML stored in the database.So,I get the html->process it(add id attribute)->want to return back after processing

  • 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-06-18T04:35:16+00:00Added an answer on June 18, 2026 at 4:35 am

    you can put the viewContent inside #mainWrap using javascript.
    just make sure the DOM is loaded wrapping your js code with $(document).ready()
    and add:

    $('#mainWrap').html(viewContent);
    

    at the end of your function.

    $(document).ready(function () {
        var getSavedContent = '<?php echo json_encode($IdLessContent); ?>';
        var trimmedCont=($.trim(getSavedContent).slice(1));
        //console.log(trimmedCont);
        var lengthCont= trimmedCont.length;
        var trimmedCont=$.trim(trimmedCont.slice(0,lengthCont-1));
        console.log(trimmedCont);
        var test = $('<div class="addId">');
        test.append(trimmedCont);
        //console.log(test.html());
        test.children().each(function(index, value) {
            $(this).attr('id', "com-"+randomString());
        });
        //console.log(test.html());  
        viewContent  = test.html();
        // put viewContent in the innerHtml of your wrapper
        $('#mainWrap').html(viewContent);
    

    });

    if you need to send back info to the server you have to do it with ajax.
    I added a javascript function addId() that will be invoked on click on one of the elements.
    the new code is:

    $(document).ready(function () {
        var getSavedContent = '<?php echo json_encode($IdLessContent); ?>';
        var trimmedCont=($.trim(getSavedContent).slice(1));
        //console.log(trimmedCont);
        var lengthCont= trimmedCont.length;
        var trimmedCont=$.trim(trimmedCont.slice(0,lengthCont-1));
        console.log(trimmedCont);
        var test = $('<div class="addId">');
        test.append(trimmedCont);
        //console.log(test.html());
        test.children().each(function(index, value) {
            $(this).attr('id', "com-"+randomString());
        });
        //console.log(test.html());  
        viewContent  = test.html();
        // put viewContent in the innerHtml of your wrapper
        $('#mainWrap').html(viewContent);
        $('#mainWrap .addId').children().click(function({
          addId(this);
        }));
    }
    
    
    addId = function(elem){
      // elem is the child element you clicked on
      // $(elem).attr('id') should be "com-[randomString]"
        $.ajax({
            type: "POST",
            url: "path/to/php/script", // update id PHP script
            data: data, // whatever you need in json format
            dataType: "json",
            error: function() {
            // error function you want to implement
                errorFunction();
            },
            success: function(resp) {
                // do whatever you need with the response from you PHP action
            }
        });
    };
    

    if you need to to call server with out human interaction just substitute

    $('#mainWrap .addId').children().click(function({
        addId(this);
    }));
    

    with:

    $('#mainWrap .addId').children().each(function({
        addId(this);
    }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working an application that periodically fetch data from a web service. The problem
I have a working application using python and zeromq and I would like to
I am working in an application in which I Am getting data from web
I did this JDBC code for fetching some data from the database Oracle 10g
I am working on business analytics application, where I need to fetch some data
I am working on an application which fetch the location details in a periodic
I am working in an android application and I want to work fetch details
I am working on application for Ipad.in this application i have a UIButton on
I am working an application having I18N support. In this application, based on user's
I'm working on a RESTful application using CodeIgniter and I'm unable to access my

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.