Advertisement

10.24.2007 at 06:09PM PDT, ID: 22916428
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Having number for each page of recordsets in php

Asked by satmanuk in PHP Scripting Language, PHP and Databases, MySQL Server

Tags:

Hi all,

I have a php page where i display a bunch of records from a mysql table and the amount displayed is limited to 10 per page. I have the page set so there is a next button if there are more than 10 (1 page) records.
What i want to achieve is having numbers for each page. Example if i had 45 records i would see 1,2,3,4 and i could click the corresponding number to get to that page of records.
I know this can be done but i dont know how far off i already am.

Hope you can help.

Thanks in advance

My code:

<?php require_once('Connections/EE_con.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_EE_con, $EE_con);


if ($_POST['radioprice']=="radio1") {
   $where_clause = "";
} elseif ($_POST['radioprice']=="radio2") {
  $where_clause = "WHERE price < 150000";
} elseif ($_POST['radioprice']=="radio3") {
   $where_clause = "WHERE price BETWEEN 150000 AND 250000";
} elseif ($_POST['radioprice']=="radio4") {
   $where_clause = "WHERE price BETWEEN 250000 AND 350000";
} elseif ($_POST['radioprice']=="radio5") {
   $where_clause = "WHERE price > 350000";
   }
//$where_clause = "WHERE price > 150000";

$query_Recordset1 = "SELECT * FROM properties $where_clause";

//$query_Recordset1 = "SELECT * FROM properties WHERE price > 150000";

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $EE_con) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false &&
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false &&
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>For Sale</title>
<style type="text/css" media="screen">
<!--
@import url("p7pm/p7pmh14.css");
@import url("bartstyles/bart2colfluidh.css");
-->
</style>
<!--[if lte IE 6]>
<style type="text/css">
a {height: 1em;}
#pagewrapper{
width:expression(parseInt(this.currentStyle.marginLeft)+parseInt(this.currentStyle.marginRight)-document.body.clientWidth>=-720?"720px":"auto");}
</style>
<![endif]-->
<!--[if IE 5]>
<style type="text/css">
#copyrightdiv {margin-top: -20px;}
</style>
<![endif]-->
</head>

<body>
<div id="pagewrapper">

<div id="masthead">
<div id="logodiv">
<img src="images/barthz_logo.jpg" alt="Bartlett - Established 1884 in New York City" width="273" height="130"></div>
</div>
<div id="menubar">
<ul id="p7PMnav">
<li><a href="aboutus.php">About Us </a></li>
<li><a href="forsale.php">Property For Sale </a></li>
<li><a href="forrent.php">Property For Rent </a></li>
<li><a href="contactus.php">Contact Us </a></li>
</ul>
<div class="clearmenu">&nbsp;</div>
</div>
<div id="mainbox">
<div id="sidebar">
<h3 class="top"><a href="admin.php">Admin</a></h3>
<form name="form1" method="post" action="forsale.php">
  <p>&nbsp;    </p>
  <p>
    <input name="radioprice" type="radio" value="radio1" checked />
    <strong>All Properties   </strong></p>
  <p>
    <input name="radioprice" type="radio" value="radio2" />
    <strong>up to &pound;150,000 </strong></p>
  <p>
    <input name="radioprice" type="radio" value="radio3" />
    <strong>&pound;150,000 - &pound;250,000</strong> </p>
  <p>
    <input name="radioprice" type="radio" value="radio4" />
    <strong>&pound;250,000 - &pound;350,000</strong> </p>
  <p>
    <input name="radioprice" type="radio" value="radio5" />
    <strong>&pound;350,000 and above </strong></p>
  <p>&nbsp;</p>
  <p>
    <input type="submit" name="submit" value="Search" />
</p>
</form>
<p>&nbsp;</p>
</div>
<div id="maincontent">
<h1>Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?></h1>
<p align="center"><a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"></a>&nbsp;<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"></a></p>
<table width="500" border="0" align="center">
 
  <?php do { ?>
   
    <tr>
      <td rowspan="2"><a href="detail.php?recordID=<?php echo $row_Recordset1['propertyid']; ?>"><img src="<?php echo $row_Recordset1['pic1']; ?>" width="130" border="0" /></a></td>
      <td><?php echo $row_Recordset1['propertyname']; ?></td>
    </tr>
    <tr>
      <td><?php echo $row_Recordset1['propertydesc']; ?></td>
    </tr>
    <tr>
      <td><a href="update.php?propertyid=<?php echo $row_Recordset1['propertyid']; ?>">Update</a></td>
      <td><a href="confirmDelete.php?propertyid=<?php echo $row_Recordset1['propertyid']; ?>">Delete</a></td>
        

    </tr>
    <tr>
      <td>&nbsp; <a href="detail.php?recordID=<?php echo $row_Recordset1['propertyid']; ?>"><?php echo $row_Recordset1['prop_detail']; ?></a></td>
      <td><?php
        $price = $row_Recordset1['price'];
        $price_formatted = number_format($price);
        echo "£" . $price_formatted;
        
        ?>
        
        </td>
    </tr>
    <tr>
      <td colspan="2"><a href="detail.php?recordID=<?php echo $row_Recordset1['propertyid']; ?>"></a><hr></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<br>
<table border="0" width="50%" align="center">
  <tr>
    <td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a>
          <?php } // Show if not first page ?>
    </td>
    <td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
          <?php } // Show if not first page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a>
          <?php } // Show if not last page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a>
          <?php } // Show if not last page ?>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></p>
</div>

</div>

<div id="copyrightdiv">
<div id="copyrightnotice">
<img src="images/barthz_copyright.jpg" alt=" Development" width="292" height="26"></div>
</div>
<div id="footer">
<p></p>
<p>Contact Information | Press Releases</p>
</div>

</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);


?>
Start Free Trial
[+][-]10.24.2007 at 10:38PM PDT, ID: 20145311

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP and Databases, MySQL Server
Tags: php
Sign Up Now!
Solution Provided By: Roonaan
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.25.2007 at 04:17AM PDT, ID: 20146531

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.26.2007 at 11:16AM PDT, ID: 20157865

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628