Fixed catalog using while and not foreach, since now we will grab shit from sql.

This commit is contained in:
ui0ppk 2023-02-05 13:17:29 +02:00
parent e417fde7c1
commit 8debbbf68f
1 changed files with 27 additions and 23 deletions

View File

@ -62,12 +62,12 @@ $getitstarted->header();
</ul> </ul>
<li class="list-group-item"> <li class="list-group-item">
<h5>Legend</h5> <h5>Legend</h5>
<span class="badge bg-success" style="width: 3.5rem;">Limited</span> <span class="badge bg-success" >Limited</span>
<br> <br>
<p class="text-white">Limited Items </p> <p class="text-white">Limited Items </p>
<p>Owners of these discontinued items can re-sell them to other users at any price.</p> <p>Owners of these discontinued items can re-sell them to other users at any price.</p>
<div class="pt-2"></div> <div class="pt-2"></div>
<span class="badge bg-success" style="width: 4.5rem;">Limited <span class="badge bg-danger" style="width: 1.1rem;">U</span> <span class="badge bg-success">Limited <span class="badge bg-warning text-dark">U</span>
</span> </span>
<br> <br>
<p class="text-white">Limited Unique Items</p> <p class="text-white">Limited Unique Items</p>
@ -80,27 +80,36 @@ $getitstarted->header();
$q = $con->prepare(str_replace('allStar', 'count(*)', $sql)); $q = $con->prepare(str_replace('allStar', 'count(*)', $sql));
$q->execute(); $q->execute();
$numberOfItems = $q->fetchColumn(); $numberOfItems = $q->fetchColumn();
$sql = "SELECT allStar FROM catalog LIMIT :limit OFFSET :offset";
$page = $_GET['p'] ?? 0;
$limit = 20;
$lpage = $limit*$page;
$q = $con->prepare(str_replace('allStar', '*', $sql)); $q = $con->prepare(str_replace('allStar', '*', $sql));
$q->bindParam(':limit', $limit, PDO::PARAM_INT);
$q->bindParam(':offset', $lpage, PDO::PARAM_INT);
$q->execute(); $q->execute();
if ($numberOfItems >= 1) { if ($numberOfItems >= 1) {
while ($item = $q->fetch()) { foreach ($q->fetchAll() as $item) {
$qq = $con->prepare("SELECT * FROM users WHERE id = :id"); $query = $con->prepare('SELECT COUNT(id) FROM users WHERE id=:id');
$qq->bindParam(':id', $item["creator"], PDO::PARAM_INT); $query->bindParam(':id', $_SESSION['user'], PDO::PARAM_INT);
$qq->execute(); $query->execute();
$creator = $qq->fetch(); $userExists = $query->fetchColumn();
if(!$creator) { if($userExists <= 1) {
$creator = [ $creator = [
"id" => $_SESSION['user'],
"username" => $item["name"]
];
} else {
$creator = [
"id" => 0, "id" => 0,
"username" => "[ unknown user ]" "username" => "[ unknown user ]"
]; ];
} }
$x = 40;
for ($i = 1; $i <= $x; $i++) {
?> ?>
<div class="position-relative col"> <div class="position-relative col">
<div class="card shadow-sm h-100"> <div class="card shadow-sm h-100 d-inline-block">
<a href="item.php?id=<?php echo (int)htmlspecialchars($item["id"]); ?>"><img src="<?php if (!empty($item["thumbnail"])) {echo htmlspecialchars($item["thumbnail"]);} else {echo "assets/placeholder.png";} ?>" class="card-img-top"></a> <a href="item.php?id=<?php echo (int)htmlspecialchars($item["id"]); ?>"><img src="<?php if (!empty($item["thumbnail"])) {echo htmlspecialchars($item["thumbnail"]);} else {echo "assets/placeholder.png";} ?>" height=150 width=150 class="card-img-top"></a>
<p class="me-1 mt-1 position-absolute top-0 end-0"><?php if(rand(1, $x) == $x) { echo '<span class="badge bg-success">Limited</span>'; }; ?></p> <p class="me-1 mt-1 position-absolute top-0 end-0"><?php if($item['limited'] == 1) { echo '<span class="badge bg-success">Limited</span>'; }; ?></p>
<span class="fs-6 mt-2 ms-2 opacity-75 position-absolute top-50 start-0 translate-middle-y bg-success badge">$<?php echo (int)htmlspecialchars($item["price"]); ?></span></img> <span class="fs-6 mt-2 ms-2 opacity-75 position-absolute top-50 start-0 translate-middle-y bg-success badge">$<?php echo (int)htmlspecialchars($item["price"]); ?></span></img>
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($item["name"]); ?></h5> <h5 class="card-title"><?php echo htmlspecialchars($item["name"]); ?></h5>
@ -111,16 +120,11 @@ $getitstarted->header();
</div> </div>
</div> </div>
<?php <?php
if ($i == $x) { } } else {
break;
echo "</div>";
}
}
}
} else {
echo "</div> <h4 class='text-muted text-center'><i class='bi bi-egg-fried' style='font-size: 6rem;'></i><br> Looks like there are no items in the catalog yet...</h4>";} ?> echo "</div> <h4 class='text-muted text-center'><i class='bi bi-egg-fried' style='font-size: 6rem;'></i><br> Looks like there are no items in the catalog yet...</h4>";} ?>
<br> <br>
</div> </div>
</main> </main>
</body> </body>
</html> </html>