我需要按每个请求 50 行的限制请求数据并在搜索中找到。
这是我从 mysql 获取数据的函数:
function index()
{
$data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->load->library("pagination");
$config = array();
$config["base_url"] = base_url() . "products/index";
$config["total_rows"] = $this->products_model->products_count();
$config["per_page"] = ROWS_PER_PAGE;
$config['num_links'] = 4;
$config["uri_segment"] = 3;
//$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<div class="pagerSC">';
$config['full_tag_close'] = '<div style="clear: left;"></div></div>';
$config['cur_tag_open'] = '<span class="currentSC">';
$config['cur_tag_close'] = '</span>';
$config['prev_link'] = '< Previous';
$config['next_link'] = 'Next >';
$config['first_link'] = '<< First';
$config['last_link'] = 'Last >>';
$config['num_tag_open'] = '';
$config['num_tag_close'] = '';
$config['next_tag_open'] = '';
$config['next_tag_close'] = '';
$config['first_tag_close'] = '';
$config['last_tag_open'] = '';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$prods = $this->products_model->fetch_products($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
//$this->load->view("example1", $data);
//$products = $this->products_model->getAllProducts();
$warehouses = $this->products_model->getAllWarehouses();
$warehouse = DEFAULT_WAREHOUSE;
//if(!empty($products)) {
foreach($prods as $product) {
$id[] = $product->id;
$image[] = $product->image;
$code[] = $product->code;
$name[] = $product->name;
$size[] = $product->size;
$cost[] = $product->cost;
$price[] = $product->price;
$qt = 0;
foreach($warehouses as $house) {
$warehouse_product = $this->products_model->getProductQuantity($product->id, $house->id);
$qt += $warehouse_product['quantity'];
}
$quantity[] = $qt;
$unit[] = $product->unit;
$alert_quantity[] = $product->alert_quantity;
}
$keys = array("id","image","code","name","quantity","unit","size","cost","price","alert_quantity");
$final = array();
foreach ( array_map(null, $id, $image, $code, $name, $quantity, $unit, $size, $cost, $price, $alert_quantity) as $key => $value ) {
$final[] = array_combine($keys, $value);
}
$data['rows'] = $final;
// }
$data['warehouses'] = $warehouses;
$meta['page_title'] = $this->lang->line("products");
$data['page_title'] = $this->lang->line("products");
$this->load->view('commons/header', $meta);
$this->load->view('content', $data);
$this->load->view('commons/footer');
}
这是我的带有数据结果的 php,但都是来自 mysql 的数据,我需要像分页函数一样按需加载:
<table id="fileData" cellpadding=0 cellspacing=10 width="100%">
<thead>
<tr>
<th style="width:45px;"><?php echo $this->lang->line("image"); ?></th>
<th><?php echo $this->lang->line("product_code"); ?></th>
<th><?php echo $this->lang->line("product_name"); ?></th>
<th><?php echo $this->lang->line("quantity"); ?></th>
<th><?php echo $this->lang->line("product_unit"); ?></th>
<th><?php echo $this->lang->line("product_size"); ?></th>
<th><?php echo $this->lang->line("product_cost"); ?></th>
<th><?php echo $this->lang->line("product_price"); ?></th>
<!-- <th><?php echo $this->lang->line("alert_quantity"); ?></th> -->
<th style="width:45px;"><?php echo $this->lang->line("actions"); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $row):?>
<tr>
<td style="text-align:center;">
<?php echo '<a class="ajax" href="uploads/' . $row['image'] .'"><img src="uploads/' . $row['image'] . '" alt="' . $row['image'] . '" width="24" height="24" /></a>'; ?></td>
<td><?php echo $row['code']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['size']; ?></td>
<td><?php echo $row['cost']; ?></td>
<td><?php echo $row['price']; ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php if($links) { echo $links; } else { echo "<div class=\"pagerSC\"></div>"; }?>
任何帮助表示赞赏。