示例#1
0
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) . '">&laquo;</a></li>';
        } else {
            $subject_index .= '<li class="disabled"><a href="#">&laquo;</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) . '">&raquo;</a></li>';
        } else {
            $subject_index .= '<li class="disabled"><a href="#">&raquo;</a></li>';
        }
        $subject_index .= '</ul>';
    }
    $value = array('query' => $query, 'index' => $subject_index);
    return $value;
}
示例#2
0
while ($subject_id = mysql_fetch_array($subject_set)) {
    echo "<option value=\"{$subject_id['id']}\"";
    if ($sel_page['subject_id'] == $subject_id['id']) {
        echo " selected=\"selected\"";
    }
    echo ">{$subject_id['name']}</option>";
}
?>
					</select>
					</div>
					<label for="page_position" class="col-sm-2 control-label">Page Position</label>
					<div class="col-sm-3">
					  
					<select class="form-control" name="page_position" id="page_position">
						<?php 
$page_set = get_pages_for_admin();
$page_count = mysql_num_rows($page_set);
// $subject_count + 1 b/c we are adding a subject
echo "<option></option>";
for ($count = 1; $count <= $page_count + 1; $count++) {
    echo "<option value=\"{$count}\"";
    if ($sel_page['position'] == $count) {
        echo " selected=\"selected\"";
    }
    echo ">{$count}</option>";
}
?>
					</select>
					</div>
				  </div>