Your script won't work the way you want to.
First, you need to use a LIMIT 10 OFFSET XX in your query, or you will always fetch every records in your table
Then, you iterrate in your resultset, and get the column when you need them directly.
Just here, I used an object to get teh results. I just love object oriented...
As I understand that it can be a bit difficult to grasp if you have no idea what is
Object oriented programming, I've included the usual mysql_fetch_array() version below.
Here for the object oriented version:
PHP Code:
<?php
include ('connect/index.php')
mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
//How many rows you want to get from your table for each pages
$limit=10;
//if a parameter "page" is passed in the url, take it as the page to display, otherwise, define the page to be displayed as the first one
$currentPage=(isset($_GET['page']))?$_GET['page']:1;
//Determine the current offset to use in the query
$offset=($page-1)*$limit;
$query = "SELECT * FROM saleitems LIMIT $limit OFFSET $offset";
$result = mysql_query($query);
//$num = mysql_numrows($result); //this is not needed anymore, look the syntax I use below.
//we open our table now
echo<<<HTML
<center>Database Output</center>
<br><br>
<table border="1" cellspacing="2" cellpadding="2" align="center">
HTML;
//Now, we parse every results from our table:
while($obj=mysql_fetch_object($result)){
echo<<<HTML
<tr>
<td>
<img src="{$obj->image}" alt="image" />
<br>{$obj->name}<br>{$obj->classification}<br>{$obj->percentoff}<br>
</td>
</tr>
HTML;
}
//And we finally close the table
echo<<<HTML
</table>
HTML;
?>
And here for the usual array version:
PHP Code:
<?php
include ('connect/index.php')
mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
//How many rows you want to get from your table for each pages
$limit=10;
//if a parameter "page" is passed in the url, take it as the page to display, otherwise, define the page to be displayed as the first one
$currentPage=(isset($_GET['page']))?$_GET['page']:1;
//Determine the current offset to use in the query
$offset=($page-1)*$limit;
$query = "SELECT * FROM saleitems LIMIT $limit OFFSET $offset";
$result = mysql_query($query);
//$num = mysql_numrows($result); //this is not needed anymore, look the syntax I use below.
//we open our table now
echo<<<HTML
<center>Database Output</center>
<br><br>
<table border="1" cellspacing="2" cellpadding="2" align="center">
HTML;
//Now, we parse every results from our table:
while($ary=mysql_fetch_array($result)){
echo<<<HTML
<tr>
<td>
<img src="{$ary['image']}" alt="image" />
<br>{$ary['name']}<br>{$ary['classification']}<br>{$ary['percentoff']}<br>
</td>
</tr>
HTML;
}
//And we finally close the table
echo<<<HTML
</table>
HTML;
?>