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; }
</div> <div class="form-group" id="product_name_title"> <label for="product_name" class="col-sm-2 control-label">Product Name</label> <div class="col-sm-5"> <input type="text" class="form-control" value="<?php echo $sel_product['name']; ?> " id="product_name" name="product_name" placeholder="Product Name"> </div> <label for="product_position" class="col-sm-2 control-label">Product Position</label> <div class="col-sm-3"> <select class="form-control" name="product_position" id="product_position"> <?php $product_set = get_products_for_admin(); $products_count = mysql_num_rows($product_set); // $subject_count + 1 b/c we are adding a subject echo "<option></option>"; for ($count = 1; $count <= $products_count + 1; $count++) { echo "<option value=\"{$count}\""; if ($sel_product['position'] == $count) { echo " selected=\"selected\""; } echo ">{$count}</option>"; } ?> </select> </div> </div>