Jump to content


News & Pagination


9 replies to this topic

#1 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 20 July 2007 - 05:36 AM

I've tried to integrate this script:

<?php	
$query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY id desc";
$result = @mysql_query($query); 
if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$url = 'comments.php?id='.$row['id'];
echo '<p><b>'.$row['title'].'</b><br>
Written on '.$row['sd'].' by <b>'.$row['author'].'</b><br />
'.$row['post'].'<br />
<a href="java script:openComments(\''.$url.'\')">Add new comment or view posted comments</a></p>';
}
} else {
echo 'There are no news posts to display';
}
?>


With this script that makes pages after result of the number of mysql hits but I'm unfortunaly unlucky "/


<?php
    if($_GET['page']) // Is page defined?
    {
        $page = $_GET['page']; // Set to the page defined
    }else{
        $page = 1; // Set to default page 1
    }
$max = 3; // Set maximum to 10
 
$cur = (($page * $max) - $max); // Work out what results to show
 
$getdata = mysql_query("SELECT * FROM `news_posts` ORDER BY `id` DESC LIMIT $cur, $max") or die(mysql_error()); // select the results
$data = mysql_fetch_array($getdata); // get the data
 
$counttotal = mysql_query("SELECT * FROM `news_posts` ") or die(mysql_error()); // select all records        
$counttotal = mysql_num_rows($counttotal); // count records
 
$total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show 
 
if($page > 1){ // is the page number more than 1?
                $prev = ($page - 1); // if so, do the following. take 1 away from the current page number
                echo '<a href="?page=' . $prev . '">« Previous Page </a>'; // echo a previous page link
                }
 
for($i = 1; $i <= $total_pages; $i++) // for each page number
                {
                    if($page == $i) // if this page were about to echo = the current page
                        {
                            echo'<b>' . $i .'</b> '; // echo the page number bold
                                } else {
                            echo '<a href="?page=' . $i . '">' . $i . '</a> '; // echo a link to the page
                        }
                }
 
if($page < $total_pages){ // is there a next page?
                    $next = ($page + 1); // if so, add 1 to the current
                echo '<a href="?page=' . $next . '"> Next Page »</a>'; // echo the next page link
                    } 
?>


can some one help me out ? its pretty urgent ^^^
thanks in advance and have a nice day

#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 July 2007 - 05:48 AM

Could you quickly give us the output of the script? It might help instead of scrambling through the code :D

#3 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 20 July 2007 - 07:42 AM

What output ? :S

#4 fiv3isaliv3

    Young Padawan

  • Members
  • Pip
  • 258 posts
  • Gender:Male

Posted 20 July 2007 - 11:03 AM

View Postnygorn, on Jul 20 2007, 08:42 AM, said:

What output ? :S

The resulting HTML.

#5 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 20 July 2007 - 11:17 AM

thats all the scripts :P

#6 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 20 July 2007 - 02:15 PM

They mean what is displayed on the page.
like: http://yoursite.com/news.php
What is outputted there?

#7 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 20 July 2007 - 03:46 PM

http://kalank4.100we...e.net/index.php

and when i tries it gets like:

< Previous Page 1 2 3...
Result goes here

< Previous Page 1 2 3...
Result goes here

< Previous Page 1 2 3...
Result goes here

< Previous Page 1 2 3...
Result goes here

So it doesnt put the 4:th result on the next page :S

#8 _*Creative Insanity_*

  • Guests

Posted 20 July 2007 - 04:02 PM

Look at P2L home and do a search and on the subject you will find this.

#9 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 20 July 2007 - 04:49 PM

dude, the second codebox contains the page system i try to integrate in the news system...
the tutorial of the page was made by adam on p2l ^^

#10 nygorn

    Young Padawan

  • Members
  • Pip
  • 53 posts
  • Gender:Male
  • Location:Sweden

Posted 22 July 2007 - 06:42 PM

um.. gone almost 3 days now... any one going to help me or is it impossible to alter that script with the pagination script?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users