I have code a productlist and I have tested to put in a code for the dynamic links so the pages wouldnt be so long but I cant get it to work
Here is the pruductlist.php code
<?php
session_start();
// database connection code here
$dbname = '****'; // the name of the database
$dbhost = 'localhost'; // 99% chances you won't need to change this value
$dbusername = '****'; // your MySQL username
$dbpassword = '****';
$connection=mysql_connect($dbhost, $dbusername, $dbpassword) or die(mysql_error());
$dbase=mysql_select_db($dbname) or die(mysql_error());
// Check if there's a $cat_id variable passed in, output correct query
if(isset($cat_id))
{
$query = "SELECT * from graphics where category_id='$cat_id' ";
}
// If both variables are not present, output default query
if(!isset($cat_id))
{
$query = "SELECT * from graphics ";
}
// execute query
$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());
// PUT INCLUDE STATEMENT HERE
include('../top.php');
echo "<td width=\"100%\" valign=\"top\">";
echo "<b><p class=\"head\">Category: $cname[category_name]</b>";
echo "<p class=\"content\">";
// Count the rows to see if there were any results
$total = @mysql_num_rows($result);
echo "Total graphics available for download: $total";
while ($row = mysql_fetch_array($result))
{
$id=$row["graphics_id"];
$name=$row["graphics_name"];
$cat_id=$row["category_id"];
$designer=$row["designer"];
$email=$row["email"];
$date=$row["date"];
$image=$row["image"];
$dsc = $row["description"];
$viewlink=$row["viewlink"];
$downloadlink=$row["downloadlink"];
$views = $row["views"];
$downloads = $row["downloads"];
// query category table for category name.
$catquery = "SELECT category_name from category where category_id='$cat_id' ";
$result2= mysql_query($catquery) or die
("Could not execute query : $catquery." . mysql_error());
$cname = mysql_fetch_array($result2);
// Now print out the catalog display
?>
</b><p class="content">
<table border="1" cellpadding="0" cellspacing="2" style="border-collapse: collapse" width="90%" class="cell">
<tr>
<td width="100%" height="17" colspan="2"><p class="head"><?php echo "$cname"; ?>
</td>
</tr>
<tr>
<td width="10%"><p class="content">
<?php
if (!(empty($image))) // image field is not empty
{
echo "<img src=$image border=0 alt=$name width=150 align=right>";
}
?>
</td>
<td width="60%">
<p class="content">
<?php echo "$dsc"; ?><p class="content">
<?php echo "$date"; ?>
<br>
Skickad av:<a href="mailto:<?php echo "$email"; ?>"><?php echo "$designer"; ?></a><br>
<p class="content">
<?php echo "<a href=\"download.php?id=$id\">Download </a>[ $downloads ]";?><br>
<?php echo "<a href=\"view.php?id=$id\" target=\"_blank\">View</a> [ $views ]"; ?><p>
</td></tr></table><p>
<?php
} // end of while
?>
</td>
</tr>
</table>
<br>
<? include('../footer.php'); ?>
Here is the dynamic links code part 1
// dynamic navigation variables
$rows_per_page=5; // adjust the number here to display number of entries per page
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);
if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q .= "LIMIT $start, $rows_per_page";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());
Part 2
<?php
}
// Display dynamic navigation here
// create the dynamic links
if ($screen > 0) {
$j = $screen - 1;
$url = "$PHP_SELF?screen=$j";
echo "<a href=\"$url\">Prev</a>";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "$PHP_SELF?screen=" . $i;
$j = $i + 1;
echo " | <a href=\"$url\">$j</a> | ";
}
if ($screen < $pages-1) {
$j = $screen + 1;
$url = "$PHP_SELF?screen=$j";
echo "<a href=\"$url\">Next</a>";
}
?>
Problem is that I use the same code in my guestbok and my blog/news code without any problems why is it problem in this code?
🙁
/Kiara