Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Epiales
Posts: 1119 Joined: Thu Aug 15, 2013 1:38 am
Post
by Epiales » Sat Oct 12, 2013 3:28 am
Hey all,
In the middle of switching to mysqli, my pagination stopped working on the market. I don't see any reason why it shouldn't work. Any help would be great.
Code:
Code: Select all
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 5;
$counter = 0;
$sql = "SELECT * FROM market ORDER BY amount DESC LIMIT $start_from, 5";
$user_query = mysqli_query($db_conx, $sql);
?>
<div>
<div align="center" class="float-left">Name</div>
<div align="center" class="float-center">Amount</div>
<div align="center" class="float-right">Price</div>
</div>
<br><br>
<?php
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
?>
<form action="market.php" method="post">
<div>
<div align="left" class="left"><?php echo $row["name"]; ?></div>
<div align="center" class="center"><?php echo number_format($row["amount"]); ?></div>
<div align="center" class="right"><?php echo number_format($row["price"]); ?></div>
<input type="hidden" id="hidden" name="hidden" value="<?php echo $row["mid"]; ?>">
<div align="center"><?php echo "<A href='market.php?mid=$row[mid]'?><font color='red'>Purchase" ?>;</a></font></div>
</div>
</form>
<?php
$counter = 1;
}
if ($counter == 0)
{
echo '<span id="errormess"><big><font color="red"><b>There are currently no sellers at this time!</b></font></big></span>';
}
?>
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 5;
$sql = "SELECT COUNT(name) FROM market";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
$total_records = $row[0];
$total_pages = ceil($total_records / 5);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='market.php?page=".$i."'>".$i."</a> ";
};
?>
Everything works fine. I can post to the market and buy from the market. The pagination just stopped and wont' show the pages
Last edited by
Epiales on Sat Oct 12, 2013 3:52 am, edited 1 time in total.
Epiales
Posts: 1119 Joined: Thu Aug 15, 2013 1:38 am
Post
by Epiales » Sat Oct 12, 2013 3:51 am
Epiales wrote: Hey all,
In the middle of switching to mysqli, my pagination stopped working on the market. I don't see any reason why it shouldn't work. Any help would be great.
Code:
Code: Select all
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 5;
$counter = 0;
$sql = "SELECT * FROM market ORDER BY amount DESC LIMIT $start_from, 5";
$user_query = mysqli_query($db_conx, $sql);
?>
<div>
<div align="center" class="float-left">Name</div>
<div align="center" class="float-center">Amount</div>
<div align="center" class="float-right">Price</div>
</div>
<br><br>
<?php
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
?>
<form action="market.php" method="post">
<div>
<div align="left" class="left"><?php echo $row["name"]; ?></div>
<div align="center" class="center"><?php echo number_format($row["amount"]); ?></div>
<div align="center" class="right"><?php echo number_format($row["price"]); ?></div>
<input type="hidden" id="hidden" name="hidden" value="<?php echo $row["mid"]; ?>">
<div align="center"><?php echo "<A href='market.php?mid=$row[mid]'?><font color='red'>Purchase" ?>;</a></font></div>
</div>
</form>
<?php
$counter = 1;
}
if ($counter == 0)
{
echo '<span id="errormess"><big><font color="red"><b>There are currently no sellers at this time!</b></font></big></span>';
}
?>
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 5;
$sql = "SELECT COUNT(name) FROM market";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
$total_records = $row[0];
$total_pages = ceil($total_records / 5);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='market.php?page=".$i."'>".$i."</a> ";
};
?>
Everything works fine. I can post to the market and buy from the market. The pagination just stopped and wont' show the pages
I fixed it, but kept the post here in case others would like to see how it was fixed!
Funny how you can spend an hour or two trying to figure out, but the second you post here, you figure it out LOL.... So here's what I did.
I took:
Code: Select all
$numrows = mysqli_num_rows($user_query);
$total_records = $row[0];
and changed it to:
Code: Select all
$row = mysqli_fetch_row($user_query);
$total_records = $row[0];