UPDATE***I am attempting to paginate the result of this foreach loop. This ALMOST works. Im able to get all of the information I need to paginate, but ALL results show on each page. The record count is correct, the generated page numbers are correct. All I'm missing is having the correct number of records display to each page. I understand I need to add the "LIMIT" portion to the sql but where?
UPDATE#2 - LIMIT was working, BUT, I found that the records displayed are treated as just 1 record because they reside in a list in 1 field. So, I need to somehow explode the result into separate pieces for an accurate count. I hope that makes sense.
//$page is generated on another page and is working correctly
$sql = mysqli_query($con, "SELECT * FROM profile_tbl WHERE X_reg_id = '$var_reg_id'");
while($field = mysqli_fetch_assoc($sql)){
$list = $field['profile_choose_them'];
$list_count = preg_split("/((r?n)|(rn?))/", $list);
$records_per_page = 3;
$item_count= count($list_count);
$item_count_adj_total_records = ($row_count-1);
$total_pages = ceil($item_count_adj_total_records/$records_per_page);
$offset = (($page-1)*$records_per_page);
}
foreach(preg_split("/((r?n)|(rn?))/", $list) as $id){
$single = mysqli_query($con, "SELECT * FROM profile_tbl WHERE X_reg_id = '$id'");
while($display = mysqli_fetch_assoc($single)){
echo '<div><img src="'.$display["profile_pic_main"] .'"></div>';
}
}
for($page=1;$page<=$total_pages;$page++){
echo '<a href="../../'.$var_return_ref.'?page='.$page.'">'.$page.'</a> ';
}
I tried this, but it does not display my items, only page numbers
$single = mysqli_query($con, "SELECT * FROM profile_tbl WHERE X_reg_id = '$id' LIMIT ($offset, $item_count_adj_total_records)");