function pagination($per_page, $case, $cat = 0) { // case 1 for subjects // case 2 for pages // case 3 for products // case 4 for users if ($per_page == 0) { $per_page = 5; } $subject_index = ''; $subj = isset($_GET['pg']) ? (int) $_GET['pg'] : 1; $start = ($subj - 1) * $per_page; // this will return $query ! switch ($case) { case "subjects": $subject_set = get_subjects_for_admin(true); $query = mysql_query("SELECT * FROM page_subjects ORDER BY id DESC LIMIT {$start},{$per_page}"); break; case "users": $subject_set = get_users_for_admin(true); $query = mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT {$start},{$per_page}"); break; case "orders": $subject_set = get_orders_for_admin(true); $query = mysql_query("SELECT * FROM orders ORDER BY id DESC LIMIT {$start},{$per_page}"); break; case "pages": $subject_set = get_pages_for_admin(true); $query = mysql_query("SELECT * FROM page_data ORDER BY id DESC LIMIT {$start},{$per_page}"); break; case "products": $subject_set = get_products_for_admin(true); $query = mysql_query("SELECT * FROM products ORDER BY id DESC LIMIT {$start},{$per_page}"); break; case "cat_products": $subject_set = get_products_for_cat($cat); $query = mysql_query("SELECT * FROM products WHERE subject_id = {$cat} ORDER BY id DESC LIMIT {$start},{$per_page}"); break; default: echo "No case selected for pagination !"; break; } $subject_total = ceil(mysql_result($subject_set, 0) / $per_page); $category_link = ''; if ($cat > 0) { $category_link = 'subject=' . $cat . '&'; } // return pagination ! if ($subject_total >= 2 && $subj <= $subject_total) { $subject_index .= '<ul class="pagination pagination-sm">'; if (isset($_GET['pg']) && $_GET['pg'] > 1) { $subject_index .= '<li><a href="?' . $category_link . 'pg=' . ($_GET['pg'] - 1) . '">«</a></li>'; } else { $subject_index .= '<li class="disabled"><a href="#">«</a></li>'; } for ($x = 1; $x <= $subject_total; $x++) { $subject_index .= $x == $subj ? '<li class="active"><a href="?' . $category_link . 'pg=' . $x . '">' . $x . '</a></li> ' : '<li><a href="?' . $category_link . 'pg=' . $x . '">' . $x . '</a></li> '; } if (isset($_GET['pg']) && $_GET['pg'] < $subject_total) { $subject_index .= '<li><a href="?' . $category_link . 'pg=' . ($_GET['pg'] + 1) . '">»</a></li>'; } else { $subject_index .= '<li class="disabled"><a href="#">»</a></li>'; } $subject_index .= '</ul>'; } $value = array('query' => $query, 'index' => $subject_index); return $value; }
require_once '../includes/admin_header.php'; require_once 'includes/admin_functions.php'; ?> <div class="row"> <?php include 'admin_sidebar.php'; ?> <article class="col-lg-9"> <form id="options" class="form-horizontal" action="subject_action.php" role="form" method="post" enctype="multipart/form-data" onsubmit="return postSubject()"> <?php $subject_set = get_subjects_for_admin(); $subject_count = mysql_num_rows($subject_set) + 1; ?> <input type="hidden" name="subject_position" id="subject_position" value="<?php echo $subject_count; ?> " /> <div class="form-group"> <label for="subject_name" class="col-sm-2 control-label">Name</label> <div class="col-sm-10"> <input type="text" class="form-control" id="subject_name" name="subject_name" placeholder="Subject Name"> </div> </div> <div class="form-group"> <label for="subject_nav" class="col-sm-2 control-label">Navigation</label>