UK Webmaster Talk - Online Marketing - SEO


 

Pageation

This is a discussion on Pageation within the Php and MySQL forums, part of the Programming / Scripting / Coding category; I am able to view a specific recored from a db and also i am able to view all of ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Website Design & Development > Programming / Scripting / Coding > Php and MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 08-05-2005, 19:28   #1 (permalink)
WMT Addict
 
Join Date: Apr 2005
Location: Brighton,UK
Posts: 162
iTrader: 0 / 0%
asgsoft is on a distinguished road
Default Pageation

I am able to view a specific recored from a db and also i am able to view all of them. how can i make either or both of the following:

1- a drop down menue to select how many records in a page with a next button that views the next lot

2- a page that displays a record a page with a next and previos button. the first record will not have a previos button and the last record will not have a next button.

I am using this to achieve both targets,but it doesn't work all the way through:

PHP Code:

<form name="form1" method="post" action="pages.php">

show 

<select name="select">

<option value="1" selected>1</option>

<option value="5">5</option>

<option value="10">10</option>

<option value="20">20</option>

<option value="50">50</option>

<option value="100">100</option>

</select>

Per page 

<input type="submit" name="Submit" value="Submit">

</form>

<?php 

 

// Database Connection 

include 'db.php'

 

// If current page number, use it 

// if not, set one! 

$number $_POST['select'];

 

if(!isset(
$_GET['page'])){ 

$page 1

} else { 

$page $_GET['page']; 



 

// Define the number of results per page 

$max_results $number

 

// Figure out the limit for the query based 

// on the current page number. 

$from = (($page $max_results) - $max_results); 

 

// Perform MySQL query on only the current page number's results 

 

$sql mysql_query("SELECT * FROM school LIMIT $from, $max_results"); 

while(
$row mysql_fetch_array($sql)){ 

// Build your formatted results here. 

echo $row['title']."<br />"

echo 
$row['id']."<br />"

        echo 
$row['make']."<br />"

        echo 
$row['name']."<br />"

        echo 
$row['colour']."<br />"

        echo 
$row['trainer info 1']."<br />";

        echo 
$row['trainer info 2']."<br />"

        echo 
$row['stock']."<br />";

        echo 
$row['price']."<br />";



 

// Figure out the total number of results in DB: 

$total_results mysql_result(mysql_query("SELECT COUNT(*) as Num FROM school"),0); 

 

// Figure out the total number of pages. Always round up using ceil() 

$total_pages ceil($total_results $max_results); 

 

// Build Page Number Hyperlinks 

echo "<center>Select a Page<br />"

 

// Build Previous Link 

if($page 1){ 

$prev = ($page 1); 

echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> "



 

for(
$i 1$i <= $total_pages$i++){ 

if((
$page) == $i){ 

echo 
"$i "

} else { 

echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "





 

// Build Next Link 

if($page $total_pages){ 

$next = ($page 1); 

echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"



echo 
"</center>"

?>


and i get this warning:



Quote:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\asgsoft\www\school\pages.php on line 39



Warning: Division by zero in c:\asgsoft\www\school\pages.php on line 56




but the actual function of which is to select how many to view on a page partially works because it works for the first page only. but on page 2 it shows only 1 trainer rather than whater i originally told it.

thank you very much
asgsoft is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
pageation

« ipb | Upload Error »
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 16:44.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41