Jump to content

Recommended Posts

Hi I have never tried doing this before can someone please give me some tips on how to make this so that if it diplays 5 results per page from the database it will autmatically show links at the bottom of the page to click to page 2 3 etc if there are more than 5 results called from the database. Any tips would be appreciated thanks.

 

<? 
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();
error_reporting(7);
require("global/admin_functions.php");
include("results.php");
$sid = $_SESSION['LOGINID'];

if($sid!="")
{
$sql 	= "select * from tbluserdetails where intAccountID=$sid";
$temps  = $DB_site->query($sql);
if($row=$DB_site->fetch_array($temps))
{


	$username   = $row["username"];
	$email      = $row["email"];
	$company    = $row["company"];
	$position   = $row["position"];
	$lname      = $row["lastname"];
	$fname      = $row["firstname"];
	$street     = $row["street"];
	$city       = $row["city"];
	$state      = $row["state"];
	$postal     = $row["postal"];
	$country    = $row["country"];
	$password   = $row["password"];
	$accountid  = $row["intAccountID"];

}
}
else
{
header ("location: ../../invalid.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>H & M Trading</title>
<link rel="stylesheet" type="text/css" href="user.css" />
</head>

<body>
<div id="wrapper">
         <div id="header">
        <span class="logo">
	 </span>

		   
	 </div>
         <div id="navigation">

<div id="tabs25">
<ul>

<li><a href="../index.php" title="Home">Home</a></li>
<li><a href="../services.php" title="Services">Services</a></li>
<li><a href="../wanted.php" title="Wanted">Wanted</a></li>
<li><a href="../products.php" title="Products">Products</a></li>
<li><a href="../placead.php" title="Post Ad">Post Ad</a></li>
<li><a href="../editad.php" title="Edit Ads">Edit Ads</a></li>
<li><a href="../contact.php" title="Contact us">Contact Us</a></li>
<li><a href="../logout.php" title="Logout">Logout</a></li>
</ul>
</div>			 
		   
	 </div>



	 <div id="content">

      
<table class="viewads">
<tr><td><h1>MY ADS</h1></td></tr>
<tr><td>
<table class="viewadscont">
<tr><td class="pix"> </td><td class="titleh" align="center">TITLE</td><td class="category">CATEGORY</td><td class="statush">STATUS</td><td class="action">ACTION</td></tr>
<?
$sql="select * from tbladvertdetails where intAccountID=$sid order by intAdvertID ASC";
$tempdata=$DB_site->query($sql); 
$adcount =$DB_site->num_rows($tempdata);{
while($row=$DB_site->fetch_array($tempdata))

{
$adid           = $row["intAdvertID"];
$title          = $row["title"];
$category       = $row["category"];
$subcategory    = $row["subcategory"];
$status         = $row["status"];
$thumbnail1     = $row["thumbnail1"];
$description1   = $row["description1"];

if ($status =="Active")
{
$classtype = "statusok";
}
if ($status =="Pending")
{
$classtype = "statusx";
}

if ($adcount > 0)
   {
if ($thumbnail1 ==true) {
   echo '<tr><td class="pix"><img src="editpic1.php?adid='.$adid.'" alt="'.$description1.'" /></td>
         <td class="title"><a href=myadsview.php?adid='.$adid.'>'.$title.'</a></td><td class="category">'.$category.' / '.$subcategory.'</td><td class="'.$classtype.'">'.$status.'</td><td class="action"><a href="myadsview.php?adid='.$adid.'" >EDIT</a>  <a href="deletead.php?adid='.$adid.'&action=delete" >DELETE</a></td></tr>'; 

                        }
}
if ($thumbnail1 ==false) {
   echo '<tr><td class="pix"><img src="../../pix/noimages.png"  /></td>
         <td class="title"><a href=myadsview.php?adid='.$adid.'>'.$title.'</a></td><td class="category">'.$category.' / '.$subcategory.'</td><td class="'.$classtype.'">'.$status.'</td><td class="action"><a href="myadsview.php?adid='.$adid.'" >EDIT</a>  <a href="deletead.php?adid='.$adid.'&action=delete" >DELETE</a></td></tr>'; 
                        }
}
if ($adcount == false)
   {
   echo '<tr><td class="noads" colspan="5" class="none">You have not yet placed any ads.</td></tr>';
   }
?>


</table>
</td>
</tr>
</table>
          		 

	 </div>

	 <div id="footer">
<table>
<tr><td width="720" align="center">
<p>H & M Trading ©2008</p>		
</td><td width="240"> </td></tr>
</table>
		    
     </div>   </div>
   
</body>
</html>
<?
}
?>

My Constant Source of Suffering is over got it integrated easily but you are right css is painful sometimes but you find a good layout just stick with it. As they say if it aint broken dont fix it.

 

That little snippet you sent me to was great just had to remove the db connection parts and it works a treat except for one thing when i am on page two it still tells me i can fo to the first or previous page I am going to play around with it i shall probably break it lol

See that's the great thing about commenting your code; you can easily figure out where to go.

 

If you change the condition to > 2, the << and < links won't show unless you are on page 3++.

 

// if not on page 1, don't show back links  
if ($currentpage > 2) {  // <---- changed from 1 to 2
   // show << link to go back to page 1  
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";  
   // get previous page num  
   $prevpage = $currentpage - 1;  
   // show < link to go back to 1 page  
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";  
} // end if   

 

If you want to show the < (previous) but not the << (first), split it up into two conditions:

 

// if not on page 1, show << (first) link
if ($currentpage > 1) {  
   // show << link to go back to page 1  
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";  
} // end if   
// if on page 3 or higher, show < (previous) link
if ($currentpage > 2) {
   // get previous page num  
   $prevpage = $currentpage - 1;  
   // show < link to go back to 1 page  
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";  
} // end if   

sorry i didn't actually read this message till I have done it i just changed it all to get it working the first bit i found a work around quite easily but the second part on the second from last value took a bit of thinking. Here is what I ended up with.

 

<?   
// range of num links to show   
$range = 3; 

if ($currentpage ==2) {   
   $prevpage = $currentpage - 1;     
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> ";   
}   
    
if ($currentpage > 2) {   
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>FIRST</a> ";   
   $prevpage = $currentpage - 1;     
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> ";   
}   
   
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {   
   if (($x > 0) && ($x <= $totalpages)) {      
      if ($x == $currentpage) {     
         echo " [<b>$x</b>] ";     
      } else {   
     echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";   
      }    
   }     
}  
if ($currentpage == $totalpages -1) {       
   // echo forward link for lastpage   
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>NEXT</a> ";   
} 

else { 

if ($currentpage != $totalpages) {   
   // get next page   
   $nextpage = $currentpage + 1;   
    // echo forward link for next page    
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>NEXT</a> ";   
   // echo forward link for lastpage   
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>LAST</a> ";   
} 
}
?>

 

Now on the second and second from last it only shows previous and next thanks for the help again :)

mm I am having on last problem with the following code it displays the error message No Ads have been placed in this section yet but below that it is still saying NEXT LAST as page selections the end of thre url says .php?currentpage=0

 

how can I get it so it doesn't display anything do I need to use another if clause?

dont worry solved it with this thanks for the help again.

 

<?   
// range of num links to show   


$range = 3; 




if ($currentpage ==2) {   
   $prevpage = $currentpage - 1;     
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> ";   
}   
    
if ($currentpage > 2) {   
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>FIRST</a> ";   
   $prevpage = $currentpage - 1;     
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>PREVIOUS</a> ";   
}   
   
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {   
   if (($x > 0) && ($x <= $totalpages)) {      
      if ($x == $currentpage) {     
         echo " [<b>$x</b>] ";     
      } else {   
     echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";   
      }    
   }     
}  
if ($currentpage == $totalpages -1) {       
   // echo forward link for lastpage   
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>NEXT</a> ";   
} 

else { 

if ($currentpage != $totalpages) {   
   // get next page   
   $nextpage = $currentpage + 1;   
    // echo forward link for next page    
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>NEXT</a> ";   
   // echo forward link for lastpage   
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>LAST</a> ";   
} 
}
?>

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.