Jump to content

Split database: 20 rows a page


GetAWeapon
Go to solution Solved by cyberRobot,

Recommended Posts

Hello everyone,

 

I new to the php world and I'm only working with it for 5 days now. So I'm a noob :)

 

But I've got a good start atm, I already could connect a database with my webpage and show all my coloms I need.

 

Now I got a problem with the fact, my database is way to big to display on 1 page. To much load-time, so that's the reason why I want to split up all my products.

20 for each page, like in this tutorial: http://www.phpjabbers.com/php--mysql-select-data-and-split-on-pages-php25.html?err=1

 

I think I'm almost there, my problem is that when I click on the number from the next page (like nr 5), it doesn't show my next 20 products.

But when I look to the url, that seems ok, because I get something like this; index.php?page=1

 

Can someone help me to find out, what I did wrong? And plz, remember, if you give me an answer, plz keep it short and simple. I'm a noob at this.

 

This is my code:

<?php
include('connect-mysql.php');
if (!empty($_GET["page"])) {
    $page  = $_GET["page"];
} else {
    $page=1;
}; 
$start_from = ($page-1) * 20; 
$sqlget = "SELECT *
FROM artikel, images
LIMIT 0, 20
";

$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting');

echo "<table>";
echo "<tr><th>A_ARTCODE</th><th>A_NUMMER</th><th>A_OMSCHRN</th><th>A_REFLEV</th><th>A_WINKEL</th><th>I_ARTCODE</th><th>I_FILE</th></tr>";

while($row = mysqli_fetch_array($sqldata)){
	echo "<tr><td align='right'>";
	echo $row['A_ARTCODE'];
	echo "</td><td align='left'>";
	echo $row['A_NUMMER'];
	echo "</td><td align='left'>";
	echo $row['A_OMSCHRN'];
	echo "</td><td align='left'>";
	echo $row['A_REFLEV'];
	echo "</td><td align='right'>";
	echo $row['A_WINKEL'];
	echo "</td><td align='right'>";
	echo $row['I_ARTCODE'];
	echo "</td><td align='right'>";
	echo $row['I_FILE'];
	//echo "<img src='000000-001000".$row['I_ID']."' />";
	echo "</td></tr>";
	}
	
echo "</table>";

$sql = "SELECT COUNT(A_ARTCODE) FROM artikel";
$rs_result = mysqli_query($dbcon, $sql) or die ("mysqli query dies");
$row = mysqli_fetch_row($rs_result) or die ("mysqli fetch row dies");
$total_records = $row[0];

$total_pages = ceil($total_records / 20);

for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='index.php?page=".$i."'>".$i."</a> "; 
};
?>

I hope someone can help me.

Edited by GetAWeapon
Link to comment
Share on other sites

Oooooh yes, ofcourse, why didn't I think of that xD I just needed to replace this:

 

$sqlget = "SELECT *
FROM artikel, images
LIMIT 0, 20
";
 
 
to 
 
 
 
$sqlget = "SELECT *
FROM artikel, images
LIMIT $start_from, 20
";
 
 
Thanks for the fast support, I'm really greatfull, but I also got another question, but I'll guess I better make another topic for it or not?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.