Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-04-2009
Member
 
Join Date: May 2008
Posts: 962
Problem of pagination

I wrote a php script to display per page news. Finally in theory because in practice it is the last news that appears on all my pages. It's several days that I try but in vain. I think my code is completely wrong, but will know.

Here is my code:
PHP Code:
<?php 
  mysql_connect 
"localhost""********""**********"); 
  
mysql_select_db ("**********"); 
  
$numberofmessagesperpage ;
  
$return mysql_query ('SELECT COUNT (*) AS nb_messages FROM news'); 
  
$data mysql_fetch_array ($return); 
  
$numberofpages $data ['nb_messages']; 
  if (isset (
$_GET ['page']) && is_int ($_GET ['page']) && $_GET ['page']> && $_GET 'Page'] <$numberofpages
  
$Page $_GET ['page'] - 1
  else 
  
$Page 0
  
$return mysql_query ('SELECT * FROM news ORDER BY id DESC LIMIT'$Page.', 1'); 
  while (
$data mysql_fetch_array ($return)) 
  {
  echo 
  
'</p> 
  <div class="news"> 
  <h3>. $Data ['
title']. " 
  <em> the '
date ('d/m/Y to HHI'$data [timestamp']).' </em
  </
H3
  <
p'; 
  $content = nl2br (stripslashes ($data ['
content'])); 
  echo $content. '
</p> </div>'; 
  }
  echo '
Page:'; 
  for ($i = 1; $i <= $numberofpages; $i++) 
  {
  echo '
<a href="index.php?page='. $i.'">'. $i. '</a>'; 
  }
  ?>


If you have an idea of what will not, it would be nice to me to share your ideas
Reply With Quote
  #2  
Old 06-04-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: Problem of pagination

Well firstly, in your condition, you:
PHP Code:
is_int ($_GET ['page']) 
Even if $_GET ['page'] is a number it is not considered as integer by PHP so this test will fail whatever happens. So always be worth $Page 0.

But anyway: Most of your code is useless. In fact, you can directly use WHERE to get your page without using COUNT, LIMIT and ORDER BY ... :

PHP Code:
SELECT FROM news WHERE id $Page 
Finally, you does not escape your data to HTML output. If this is not done on purpose, there is a security hole if not done on purpose, I think it's a bad idea to use htmlspecialchariser data recording.
Reply With Quote
  #3  
Old 07-04-2009
Member
 
Join Date: May 2008
Posts: 962
Re: Problem of pagination

Thank you for the info

In fact, most of my script was made from a tutorial on the site. I don't have much control over php. It was already a good start, knowing that I learned HTML and CSS from another site.

I will try to find other examples of news and re tweak my code.
Reply With Quote
  #4  
Old 07-04-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: Problem of pagination

yes HTML and CSS is good because it does not much rigor in contrast to programming languages ...
Reply With Quote
  #5  
Old 07-04-2009
Member
 
Join Date: May 2008
Posts: 685
Re: Problem of pagination

php generates html (even css). So I see no where is the problem. Simply that your class is defined in the css related to your html page
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem of pagination"
Thread Thread Starter Forum Replies Last Post
how can developper plugin the pagination with zend framework manjava Technology & Internet 1 20-05-2011 12:22 AM
Sony VGNCS3 laptop 15 inch screen problem...LCD or CHIP problem? Mick$Tyler Hardware Peripherals 5 31-10-2010 06:49 AM
Blackberry Tour Youtube problem/facebook and phone freezing problem Lohitaksha Portable Devices 6 27-07-2010 12:10 AM
hard disk problem, clicking sound and windows problem rajat_2589 Hardware Peripherals 1 16-06-2010 11:34 PM
Toshiba satellite L305D-S5893 shutdown problem or bios update problem Colter Portable Devices 4 10-04-2010 04:19 PM


All times are GMT +5.5. The time now is 03:40 PM.