Created
January 26, 2017 16:45
-
-
Save kergalym/b01233d23d174de2f37a4bd1e8e862a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function dbSelectMenuItems($page, &$cPage, $limIndex) { | |
$conn = $this->connect->getConn(); | |
$countStmt = $conn->prepare("SELECT COUNT(id) FROM articles"); | |
$countStmt->execute(); | |
while ($countIndex = $countStmt->fetch(PDO::FETCH_NUM)) { | |
$arrID[] = $countIndex['0']; | |
} | |
// Round fractions up and iterate them into array | |
foreach ($arrID as $IndexCount): | |
$cPageNum = ceil($IndexCount / $limIndex); | |
endforeach; | |
for ($i = 0; $i < $cPageNum; $i++) { | |
$cPageArrN[] = $i; | |
} | |
/* Limit the number of returned array indexes by $limIndex */ | |
// Multiplicate to made offset and use it in limit of array indexes | |
if (isset($page)) { | |
$offset = $page * $limIndex; | |
$cPage = $cPageArrN; | |
} else { | |
$offset = 0; | |
$page = 1; | |
$cPage = $page; | |
} | |
if ($stmt = $conn->prepare("SELECT id, article_title, article_author, | |
article_category, article_text, | |
article_date, pos_category, prior_num | |
FROM articles LIMIT " . $offset . "," . $limIndex)) { | |
$stmt->execute(); | |
while ($myrow = $stmt->fetch(PDO::FETCH_ASSOC)) { | |
$arrData[] = $myrow; | |
} | |
return $arrData; | |
} else { | |
return "Извините, ничего не найдено..."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment