473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help with query to divide all data to pages (per page 10)

32
hi everyone
i want to build pagination with PHP but i cannot
for ex i have 100 number of news and i like my page show only 10 news per page so let it displays 10 page and below let it is written
page1, page2, page3, and whenever i want to click on this pages let it goes the page which is clicked
this my database sql.


Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `news` (  id int(11) NOT NULL auto_increment,  theme varchar(200) NOT NULL default '',  author varchar(100) NOT NULL default '',  date date NOT NULL default '0000-00-00',  text text NOT NULL,  PRIMARY KEY  (id)) TYPE=MyISAM;CREATE TABLE `news` (
  2.   id int(11) NOT NULL auto_increment,
  3.   theme varchar(200) NOT NULL default '',
  4.   author varchar(100) NOT NULL default '',
  5.   date date NOT NULL default '0000-00-00',
  6.   text text NOT NULL,
  7.   PRIMARY KEY  (id)
  8. ) TYPE=MyISAM;
  9. i did like this but it doesnt work
  10.  
  11.  
  12. <?  @$db=mysql_connect('localhost','username','parol');mysql_select_db('db_name');   $per_page=10;      $q="SELECT count(*) FROM `news`";$res=mysql_query($q);$row=mysql_fetch_row($res);$total_rows=$row[0];$num_pages=ceil($total_rows/$per_page); echo '<h1>news</h1>';$sql="SELECT * FROM `news` ";$result=mysql_query($sql);$num_results=mysql_num_rows($result);for ($i=0; $i<$num_results; $i++)    {    $row=mysql_fetch_array($result);     $id=$row["id"];    $author=$row["author"];    $date=$row["date"];    $tema=$row["tema"];        $text=$row["text"];     echo '<b>'.$theme.'</b><br>     <a href="/news/'.$id.'/">added by</a>: <b>'.$author.'</b>  ('.$date.')<p> '.$text.' <hr>';    }<?
  13.  
  14.  
  15. @$db=mysql_connect('localhost','username','parol');
  16. mysql_select_db('db_name');
  17.  
  18.  
  19.  
  20. $per_page=10;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. $q="SELECT count(*) FROM `news`";
  28. $res=mysql_query($q);
  29. $row=mysql_fetch_row($res);
  30. $total_rows=$row[0];
  31. $num_pages=ceil($total_rows/$per_page);
  32.  
  33. echo '<h1>news</h1>';
  34. $sql="SELECT * FROM `news` ";
  35. $result=mysql_query($sql);
  36. $num_results=mysql_num_rows($result);
  37. for ($i=0; $i<$num_results; $i++)
  38.     {
  39.     $row=mysql_fetch_array($result);
  40.  
  41.     $id=$row["id"];
  42.     $author=$row["author"];
  43.     $date=$row["date"];
  44.     $tema=$row["tema"];    
  45.     $text=$row["text"];
  46.  
  47.     echo '<b>'.$theme.'</b><br>
  48.  
  49.     <a href="/news/'.$id.'/">added by</a>: <b>'.$author.'</b> 
  50.  
  51. ('.$date.')<p> '.$text.' <hr>';
  52.     }
i need this script
if possible pls see it
Thanks for attention
Feb 28 '10 #1

✓ answered by Atli

Hey.

This is called "pagination", and it has been discussed endlessly on forums and blogs over the years (including this one).
See Google for a virtually endless amount of info on the subject.

1 1477
Atli
5,058 Expert 4TB
Hey.

This is called "pagination", and it has been discussed endlessly on forums and blogs over the years (including this one).
See Google for a virtually endless amount of info on the subject.
Feb 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: *** HAWK | last post by:
I previously posted but didnt have much response. I have written out what exactly I am trying to do with my ASP site again but hopefully clearer. I am making a site will emulate something like...
1
by: CR | last post by:
"How to" question... I have an Access Database with only one table (tblBooks) with 5 fields: id, TestNumber, Book, Author, ReadingLevel, PointValue. I would like to have alphabetical listing of...
9
by: (Pete Cresswell) | last post by:
I've got some SQL that works as far as returning a recordset from a series of UNION statements. viz: SELECT whatever UNION this UNION that UNION other
4
by: dwight0 | last post by:
I am having a problem with a query, I am not sure if i would use a join or a subquery to complete this problem. I have two queries, and i need to divide one by the other, but i cant seem to get...
2
by: Jean | last post by:
Hi, i'm on windows nt4 sp6a , sql server 7.00.0842 i have something that i don't understand. The table 'source' is taking lot of space but when i bcp out, the file take only 11MB (fixed...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
5
by: Otie | last post by:
I have a select query that groups records together, specifically baseball players and their home runs and at-bats. I want to create a query that displays , , and and that sorts ASCENDING on the ...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name....
3
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.