Jump to content

shepmom2002

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

shepmom2002's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am trying to display records from a database using pagination. Currently the first page is showing and data is being displayed correctly. The links are also available below to move from page to page, however when I click on the next page, nothing happens. I know I need to add parameters to my query string, but I'm unsure as to what I need to add. Can someone help? Here is where I am calling the page: <a href="index.php?menukey=7" accesskey="7" title="">Project 3</a> Here is my pagination: function PS_Pagination($connection, $sql, $rows_per_page = 10, $links_per_page = 5) { $this->conn = $connection; $this->sql = $sql; $this->rows_per_page = $rows_per_page; $this->links_per_page = $links_per_page; $this->php_self = htmlspecialchars($_SERVER['PHP_SELF']); if(isset($_GET['page'])) { $this->page = intval($_GET['page']); } } /** * Executes the SQL query and initializes internal variables * * @access public * @return resource */ function paginate() { if(!$this->conn) { if($this->debug) echo "MySQL connection missing<br />"; return false; } $all_rs = @mysql_query($this->sql); if(!$all_rs) { if($this->debug) echo "SQL query failed. Check your query.<br />"; return false; } $this->total_rows = mysql_num_rows($all_rs); @mysql_close($all_rs); $this->max_pages = ceil($this->total_rows/$this->rows_per_page); //Check the page value just in case someone is trying to input an aribitrary value if($this->page > $this->max_pages || $this->page <= 0) { $this->page = 1; } //Calculate Offset $this->offset = $this->rows_per_page * ($this->page-1); //Fetch the required result set $rs = @mysql_query($this->sql." LIMIT {$this->offset}, {$this->rows_per_page}"); if(!$rs) { if($this->debug) echo "Pagination query failed. Check your query.<br />"; return false; } return $rs; } /** * Display the link to the first page * * @access public * @param string $tag Text string to be displayed as the link. Defaults to 'First' * @return string */ function renderFirst($tag='First') { if($this->page == 1) { return $tag; } else { return '<a href="'.$this->php_self.'?page=1">'.$tag.'</a>'; } } /** * Display the link to the last page * * @access public * @param string $tag Text string to be displayed as the link. Defaults to 'Last' * @return string */ function renderLast($tag='Last') { if($this->page == $this->max_pages) { return $tag; } else { return '<a href="'.$this->php_self.'?page='.$this->max_pages.'">'.$tag.'</a>'; } } /** * Display the next link * * @access public * @param string $tag Text string to be displayed as the link. Defaults to '>>' * @return string */ function renderNext($tag=' >>') { if($this->page < $this->max_pages) { return '<a href="'.$this->php_self.'?page='.($this->page+1).'">'.$tag.'</a>'; } else { return $tag; } } /** * Display the previous link * * @access public * @param string $tag Text string to be displayed as the link. Defaults to '<<' * @return string */ function renderPrev($tag='<<') { if($this->page > 1) { return '<a href="'.$this->php_self.'?page='.($this->page-1).'">'.$tag.'</a>'; } else { return $tag; } } /** * Display the page links * * @access public * @return string */ function renderNav() { for($i=1;$i<=$this->max_pages;$i+=$this->links_per_page) { if($this->page >= $i) { $start = $i; } } if($this->max_pages > $this->links_per_page) { $end = $start+$this->links_per_page; if($end > $this->max_pages) $end = $this->max_pages+1; } else { $end = $this->max_pages; } $links = ''; for( $i=$start ; $i<$end ; $i++) { if($i == $this->page) { $links .= " $i "; } else { $links .= ' <a href="'.$this->php_self.'?page='.$i.'">'.$i.'</a> '; } } return $links; } /** * Display full pagination navigation * * @access public * @return string */ function renderFullNav() { return $this->renderFirst().' '.$this->renderPrev().' '.$this->renderNav().' '.$this->renderNext().' '.$this->renderLast(); } /** * Set debug mode * * @access public * @param bool $debug Set to TRUE to enable debug messages * @return void */ function setDebug($debug) { $this->debug = $debug;
  2. I am very new to php. I am getting a parse error, and I have tried several things, but can't figure out what the problem is. Here is my code: <?php // This script retrieves all the records from the customers table. echo '<h1>Customers:</h1>'; require_once ('mysqli_connect.php'); // Connect to the db. $q = "SELECT Customers.CustomerID as customerid, Customers.OldCustomerID AS oldcustomerid, Concat_WS( Customers.LastName, ',', Customers.FirstName, ' ', Customers.MiddleName ) AS Customer_Name, Concat_ws( Left( Customers.FirstName, 1 ) , Left( Customers.MiddleName, 1 ) , Customers.LastName ) AS Username, zlu_Cars.Description AS Car, zlu_CarColor.Description AS Car_Color, zlu_Computers.Description AS Computer, CASE when (Customers.IsLaptop=1) then 'Yes' when (Customers.IsLaptop=0) then 'No' end AS Laptop, zlu_Race.Description AS Race, zlu_Residence.Description AS Residence, zlu_BirthMonth.Description AS Birth_Month FROM (((((Customers INNER JOIN zlu_BirthMonth ON Customers.BirthMonthID = zlu_BirthMonth.BirthMonthID) INNER JOIN zlu_CarColor ON Customers.CarColorID = zlu_CarColor.CarColorID) INNER JOIN zlu_Cars ON Customers.CarID = zlu_Cars.CarID) INNER JOIN zlu_Computers ON Customers.ComputerID = zlu_Computers.ComputerID) INNER JOIN zlu_Race ON Customers.RaceID = zlu_Race.RaceID) INNER JOIN zlu_Residence ON Customers.ResidenceID = zlu_Residence.ResidenceID ORDER BY Customers.LastName, Customers.FirstName LIMIT 499,101" $r = @mysqli_query ($dbc, $q);// Run the query. // Count the number of returned rows: $num = mysqli_num_rows($r); I'm obviously not showing you all my code, the error is this line: $r = @mysqli_query ($dbc, $q); Error says: Parse error: parse error in D:\WebShare\PHP\ShepherdS\view_Customers.php on line 17 Any idea what I am doing wrong??? I'm completely lost!!
  3. Thank you, putting the underscore in worked!!!
  4. I am brand new to mySQL, I have used MS SQL in the past. I have written a select query in Access and the query is working perfectly. When I try to re-create the query in MySQL I am getting errors all over the place. I'm sure it is something with my syntax, but I am having trouble figuring out what I am doing wrong. I am using MySQL client version: 5.0.51a. Here is my query: SELECT Customers.CustomerID, Customers.OldCustomerID, Concat(Customers.LastName,',',Customers.FirstName, ' ', Customers.MiddleName) AS Customer Name, Concat(Left(Customers.FirstName,1), Left(Customers.MiddleName,1), Customers.LastName) AS Username, zlu_Cars.Description AS Car, zlu_CarColor.Description AS Car Color, zlu_Computers.Description AS Computer, Customers.IsLaptop AS Laptop, zlu_Race.Description AS Race, zlu_Residence.Description AS Residence, zlu_BirthMonth.Description AS Birth Month FROM (((((Customers INNER JOIN zlu_BirthMonth ON Customers.BirthMonthID = zlu_BirthMonth.BirthMonthID) INNER JOIN zlu_CarColor ON Customers.CarColorID = zlu_CarColor.CarColorID) INNER JOIN zlu_Cars ON Customers.CarID = zlu_Cars.CarID) INNER JOIN zlu_Computers ON Customers.ComputerID = zlu_Computers.ComputerID) INNER JOIN zlu_Race ON Customers.RaceID = zlu_Race.RaceID) INNER JOIN zlu_Residence ON Customers.ResidenceID = zlu_Residence.ResidenceID ORDER BY Customers.LastName, Customers.FirstName; Here is the error I am receiving: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, Concat(Left(Customers.FirstName,1), Left(Customers.MiddleName,1), Customer' at line 1 Can anyone help??
×
×
  • 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.