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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:33:43+00:00 2026-06-16T22:33:43+00:00

Please refer to the following code: var index=0; var load=0; $(td.load_ads).each(function(){ var loading=$(this); $.post(‘/self_coded_helpers/jpost_get_ads.php’,{index:index,type:’fetch_id’},function(data){

  • 0

Please refer to the following code:

    var index=0;
    var load=0;
    $("td.load_ads").each(function(){
        var loading=$(this);
        $.post('/self_coded_helpers/jpost_get_ads.php',{index:index,type:'fetch_id'},function(data){
            if($("input.exist").length > 0){
                $("input.exist").each(function(){
                    if($(this).val()==data){
                        load='0';
                    }else{
                        load='1';
                    }
                });
            }else{
                load='1';
            }
            if(load == 1){
                $.post('/self_coded_helpers/jpost_get_ads.php',{index:index,type:'fetch_details',id:data},function(data2){
                    $("div.main_ads_div").append('<input type="hidden" class="exist" name="exist" value="'+data+'">');
                    if(data2!=0){
                        loading.html(load+'--'+data2);
                    }else{
                        loading.html("Place a Free Ad Now!");
                    }
                });
            }else{
                loading.html(load+"--"+data+"Place a Free Ad Now!");
            }
        });
        index=index+1;
    });

What I did was that I appended an input element every time I looped over td.load_ads:

$("div.main_ads_div").append('<input type="hidden" class="exist" name="exist" value="'+data+'">');

Hoping I could get it on my next looping of the same .each.

But var load keep returning 1 as my input.exist length is always false in this particular case.

Is it because the input doesn’t get appended that quickly?

HTML Code:

    <table id="main_ads_table" col="7" row="4">
        <tr>
            <td colspan="8"></td>
        </tr>
        <tr>
            <td class="load_img"></td>
            <td class="load_img"></td>
            <td class="load_img"></td>
            <td class="load_img"></td>
            <td class="load_img"></td>
            <td class="load_img"></td>
            <td class="load_img"></td>
            <td class="load_img"></td>
        </tr>
        <tr>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
        </tr>
        <tr>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
        </tr>
        <tr>
            <td class="load_ads"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads priority"></td>
            <td colspan="2">
                                            <div id="main">

                                            <?php if ($this->countModules('position-12')): ?>
                                                    <div id="top"><jdoc:include type="modules" name="position-12"   />
                                                    </div>
                                            <?php endif; ?>

                                                    <jdoc:include type="message" />
                                                    <jdoc:include type="component" />

                                            </div><!-- end main -->
            </td>
            <td class="load_ads priority"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads"></td>
        </tr>
        <tr>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
        </tr>
        <tr>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads priority"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
            <td class="load_ads"></td>
        </tr>
    </table>

.POST script

    $type=$_POST['type'];
    function limit_words($string, $word_limit)
    {
        $words = explode(" ",$string);
        return implode(" ",array_splice($words,0,$word_limit));
    }

    if($type=='fetch_id'){
        $query="SELECT * FROM ads1_adsmanager_ads ORDER BY RAND() LIMIT 1";
        $db->setQuery($query);
        $ad_details=$db->loadRow();

        echo $ad_details[0];
    }elseif($type=='fetch_details'){
        $id=$_POST['id'];
        $query="SELECT * FROM ads1_adsmanager_ads WHERE id=$id";
        $db->setQuery($query);
        $ad_details=$db->loadRow();

        if(!empty($ad_details)){
            echo '<input type="hidden" name="id" value="'.$ad_details[0].'">';
            echo limit_words($ad_details[9],5);
            echo '<br />';
            echo limit_words($ad_details[10],20);
        }else{
            echo '0';
        }

    }

Added my HTML and Post Script. See if it can be of more help.

  • 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-16T22:33:44+00:00Added an answer on June 16, 2026 at 10:33 pm

    You’re making it very difficult on yourself. You don’t need to first collect ID’s or to fetch each individual ad using ajax. By just getting everything in 1 post you don’t have the problem with duplicates in the first place.

    jpost_get_ads.php:

    function limit_words($string, $word_limit)
    {
        $words = explode(" ",$string);
        return implode(" ",array_splice($words,0,$word_limit));
    }
    
    $count = (int)$_POST['count'];
    $query="SELECT id, title, description FROM ads1_adsmanager_ads ORDER BY RAND() LIMIT $count";
    $db->setQuery($query);
    $ad_details = array();
    
    while ($row = $db->loadAssoc()) {
        $key = array_search($ids, $row['id']);
        $row['title'] = limit_words($row['title'],5);
        $row['description'] = limit_words($row['description'],20);
    
        $ad_details[$key] = $row;
    }
    
    header('Content-Type: application/json');
    echo json_encode($ad_details);
    exit();
    

    The javascript

    var count = $("td.load_ads").length;
    
    $.post('/self_coded_helpers/jpost_get_ads.php', { count: count } function(ads){
       $("td.load_ads").each(function(){
          var ad = ads.unshift()
            , content;
    
          if (ad) {
             content = ad.title + "<br>" + ad.description;
          } else {
             content = "Place a Free Ad Now!";
          }
    
          $(this).html(content);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please refer to this post. I have become able to configure my web.config file
Please refer to the following code: Filename: myclass.h @interface myclass:NSObject ... @end @interface NSObject(CategoryName)
Please refer the following code snippet. I want to use the std::bind for overloaded
Please refer to the following code which continuously calls a new AsyncTask . The
Please refer to the following code, which grabs some information from a PHP script,
Please refer the following links for image and diagram. Image , diagram This is
Please refer to the following code: // // CacheObjectManagerImpl.h #import <Foundation/Foundation.h> //#import CacheObject.h @class
I have question please refer the following code to understand the question. (I removed
I am using the following code to get innerHTML of $(this) : var html=$(this).html();
Please refer to the following code of from the Javadoc of Future class: FutureTask<String>

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.