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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:30:04+00:00 2026-06-06T10:30:04+00:00

A site I’m working on takes table data, counts that table data and uses

  • 0

A site I’m working on takes table data, counts that table data and uses a standard loop to display it. Here’s some of the code:

<?php
  $output='';   
  $count=count($deal_datas);
  $face_value="";
  $deal_price="";
  //var_dump(400*20/100);
  $save_value='';       
  $save_value_present='';   
  $category_name='';    
  $cat_ids=array();
  $deal_link='';
  $address_array=array();
  $address='';
  $website_name=''; 
  $website_data=array();

  if($count!=0) {
    for($i=0;$i<$count;$i++) {
      $website_data=get_single_row("web_sites",array("id"=>$deal_datas[$i]->site_id));

      if(count($website_data)!=0) {
        $website_name=$website_data[0]->name;
      }

      $address_array=array();
      $cat_ids=explode(",",$deal_datas[$i]->sub_category_ids);

      if(count($cat_ids)!=0) {
        $where_class=array("id"=>$cat_ids[0]);
        $category_names=get_single_row("sub_category",$where_class);

        if(count($category_names)!=0) {
          $category_name=$category_names[0]->name;
        } else {
          $category_name="All";
        }
      } else {
        $category_name="All";
      }

      $face_value=str_replace("USD","",$deal_datas[$i]->deal_face_value);
      $face_value=str_replace("$","",$face_value);
      $face_value=(int)str_replace(",","",$face_value);
      $save_value_present=(int)str_replace("%","",$deal_datas[$i]->deal_save_percent);

      if($deal_datas[$i]->deal_price!="") {
        $deal_price=str_replace("USD","",$deal_datas[$i]->deal_price);
        $deal_price=(int)str_replace("$","",$deal_price);
        $save_value=$deal_price;
      } else {
        $save_value=$face_value*$save_value_present/100;
      }

      $time_zone_utc=$deal_datas[$i]->deal_oe_end_date;
      $end_date=$time_zone_utc;

      if($website_name!="kgbdeals") {
        $deal_link=base_url()."deals/iframe/".$deal_datas[$i]->slug;
      } else {
        $deal_link=$deal_datas[$i]->deal_link;
      }

      if($deal_datas[$i]->deal_address==0 or $deal_datas[$i]->deal_zip_code==0) {
        $deal_datas[$i]->deal_address="";
        $deal_datas[$i]->deal_zip_code="";
      }

      if($deal_datas[$i]->deal_zip_code!="") {
        $address_array[]=$deal_datas[$i]->deal_zip_code;
  }

      if($deal_datas[$i]->deal_address!="") {
        $address_array[]=$deal_datas[$i]->deal_address;
      }

      $address=implode(" ",$address_array);

      if($deal_datas[$i]->deal_city!="") {
        if(empty($address_array)) {
          $address.=$deal_datas[$i]->deal_city;
        } else {    
          $address.=" - ".$deal_datas[$i]->deal_city;   
        }

        //Check for valid image
        $deal_image=base_url().'uploads/deals/'.$deal_datas[$i]->slug.'.jpg';


        if(getimagesize($deal_image)) {
          $valid_image=1;
        } else {
          $valid_image=0;
        }

        if($i%2==0) {
          $output.='<div class="clsDeal_Whole_Cont clearfix">

Then it outputs the tabled list of data, etc.
Problem is, sometimes that data is sometimes 120 entries that are placed on the screen and the load takes ages.

What I want to do display the data 4 or 8 entries at a time. Then, as the user scrolls, add more in.

Alternatively – to load 4. Display them. Then load 4 more, display them. And so on, so that way the user actually gets to view the contents rather than waiting for the whole list (if this is simpler). Is that possible?

I’m not using jquery for this, though I know I would need to for the whole scroll down bit. So, would there be a way to rewrite the above php in order to display chunks of 4 until the final result is reached?

  • 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-06T10:30:05+00:00Added an answer on June 6, 2026 at 10:30 am

    You have several problems here, beginning with how you ask the question. Be sure to include all the relevant code. You have a truncated code listing that doesn’t deal with the problem at hand; how to break up a long set of data into a human readable format. You do not describe how you’re getting your initial data $deals_data. The implementation details of how your format your output is not relevant to this question. Further, your code is a bit of the mess and doesn’t follow the Single Responsibility Principle.

    You should put your data selection and display functionality into single functions:

    //returns n through z rows of data. If '0' is provided for finish, returns all rows
    function getData($start=0, $finish=0 {
      $data = array();
      if ($finish == 0) {
        //get all data
      } else {
        //get limited amount of data
      }
      return $data;      
    }
    
    //returns first $limit rows of data as an html-encoded output string
    function displayDeals($deal_data, $limit) {
      ...
    }
    

    That function should call a separate function for each of your rows:

    //Returns a string of html-encoded data for one row
    function displayRow($row_data) {
      ...
    }
    

    This displayRow function will be called $limit number of times by displayDeals. Once you get that working, it becomes much simpler to use AJAX for infinite scrolling. You simply create a php function:

    function getMoreRows($start, $numberOfRows) {
      $data = getData($start, $start+$numberOfRows);
      $output = displayDeals($data, $numberOfRows);
      return $ouput;
    }
    

    This will return that output to the AJAX function that called the php code. Because it’s encoded as HTML you simply replace whatever available div with that new string.

    Note that JQuery will make this AJAX easy, but you will need some javascript in order to make this functional, or suffer a long round-trip call to a new php page each time. The latter is easy, but avoids making the user interface smooth and lazy-loaded like you want. Here is how:

    $.ajax({ url: '/my/site',
             data: {action: 'getMoreData'},
             type: 'post',
             success: function(output) {
                          //replace your div with new data
                      }
    });
    

    On the server side you need a php page to handle the request:

    if(isset($_POST['action']) && !empty($_POST['action'])) {
        $action = $_POST['action'];
        switch($action) {
            case 'getMoreData' : getMoreRows($_POST['lastDataIndex'], $_POST['numberOfRowsToFetch']);break;
            // ...etc...
        }
    }
    

    As a minor post-script about style: you should be cautious about mixing if and if-else styles, in regards to brackets. Generally, you want you code to be tight and quickly readable, and you want to never be in doubt if code is in a block. Personally, I always use brackets with if and if-else, but you should avoid using brackets in your if statement and not in your else case at the very least. Keep an eye on human readability, or you will find that you’ll be frustrated by random bugs that arise because you assume a thing is or is not in a block when it’s the opposite case.

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

Sidebar

Related Questions

My site reads a XML file that contains information (values) for a data-table. I
Site here . Why is it that the code works for $('#club').change(function(event) but not
The site was working properly but after I modified a code file. the site
A site I am working on that is built using PHP is sometimes showing
My site is going to have some inline code (when using the foo() function...)
The site that I am working on is at a remote server. I want
Site here. If you notice, the checkmarks are align with the table. I want
A site that uses username/password for users to log in obviously needs that login
My site is up here: Green McP I'm trying to put my old WP
My site provides a javascript that shows the rate of the Dutch equivalent of

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.