Forum Moderators: coopster

Message Too Old, No Replies

how to display the images in the table with paging

         

ravii

11:21 am on Sep 10, 2008 (gmt 0)

10+ Year Member



hi can any one tell how to display the images in the table with paging
this what i did i am getting all the images in one page it self
i need only 9 images in one page and at the bottom i need the navigation bar
please help me out

here is my code

<html>
<title> Fox Innovas </title>
<body bgcolor="black">
<table BORDERCOLOR="#C6C6C6" width="100%" bgcolor='darkblue'>
<tr width="60%"><td bgcolor="DarkBlue"><font size="30" face="Monotype Corsiva" color="CadetBlue">Hakman & Co </font></td>
<td>
<tr></tr>
<tr>
<td width="65%"></td>
<td width="10%" align="Right"><font face="Garamond" color="CadetBlue"><a href="hakman3.php"><b>Login Page ¦</b></a></font></td>
<td width="15%" align="Right"><font face="Garamond" color="CadetBlue"><a href="about.php"><b>About FoxInnovas ¦</b></a></font></td>
<td width="11%" align="Left" ><font face="Garamond" color="CadetBlue"><a href="contact.php"><b>Contact Us</b></a></font></td>
</tr>
</td>
</tr>
<!--<img src="C:\apache2_2\htdocs\fox.jpg" width="60" height="50">-->
</table>
</br>
<?php
function connect()
{
$dbhost='localhost';
$dbuser='';
$dbpass='';
$conn= mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'.mysql_error());
$dbname='hakman';
mysql_select_db($dbname);
return $conn;
}
?>
<form method='GET' action='img.php'>
<?php
$c=connect();
$query="select img_name from styles";
$sql=mysql_query($query);
$result=mysql_num_rows($sql);

//echo '<font color="white">'.$result.'</font></br>';

$limit=6;
$nrow=ceil($result/6); //no of rows we get
$npages=ceil($result/$limit); // no of pages we get

//echo '<font color="white">'.$nrow.'</font> </br>';

//echo '<font color="white">'.$npages.'</font> </br>';

$page=1;
$query=mysql_query("select img_name from styles LIMIT ".($page-1)*$limit.",$limit");

echo '<table border="5" align="center" width="55%" height="60%" BORDERCOLOR="#C6C6C6" >';
for($r=1;$r<=$nrow;$r++)
{
echo '<tr>';
for($d=1;$d<=3;$d++)
{
$obj=mysql_fetch_object($sql);
$imageSrc=$obj->img_name;
$cimage="images/".$obj->img_name;
echo '<td border="1" width="25px" height="25px" name="img1"><a href="img.php?src='.$imageSrc.'"><img width="187px" height="109px" src='.$cimage.'></a></td>';
}
echo '</tr>';
}
echo '</table>';

$Nav="";
If($page > 1)
{
$Nav .= "<A HREF=\"styl.php?page=" . ($page-1) . urlencode($query) . "\"><< Prev</A>";
}
For($i = 1 ; $i <= $NumberOfPages ; $i++)
{
If($i == $page)
{
$Nav .= "<B>$i</B>";
}
Else
{
$Nav .= "<A HREF=\"styl.php?page=" . $i .urlencode($query) . "\">$i</A>";
}
}
If($page < $NumberOfPages)
{
$Nav .= "<A HREF=\"styl.php?page=" . ($page+1) . urlencode($query) . "\">Next >></A>";
}

Echo "<BR><BR>" . $Nav;
?>

</form>
<a href="hakman3.php"><font color= "Blue">Back to login Page</font></a>
</body>
</html>

thanks in advance

[edited by: eelixduppy at 1:22 pm (utc) on Sep. 10, 2008]
[edit reason] removed credentials [/edit]

d40sithui

3:42 pm on Sep 10, 2008 (gmt 0)

10+ Year Member



could this be the culprit?

$obj=mysql_fetch_object($sql);

$sql is the resource from your main query that selects everything.
This should be

$obj=mysql_fetch_object($query);

since $query is the resource for your refined query.