TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 01, 2024, 07:09:14 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,174
  • Total Topics: 21,220
  • Online today: 177
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 152
  • Total: 153
  • @rjen

Some Help Needed

Started by The Wizard, November 23, 2010, 06:30:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

The Wizard

Hello:

I'm trying to add pagination and sort into my code and I can't seem to get it to work. If someone could please take a look it would be appreciated.


//
// Capture Post part 1
// Created by The Wizard
// November 21, 2010
// Version 1.0
//
//
// script variables for customization

$P = 331; // Article page that shows the captured post
$B = 12;  // Board that you want to see all the topics from
$per_page = 2; //max displayed per page
$start = $_GET['start']; // = 0

// ****** no need to edit past this point! Your warranty is void if modified ******

require_once('SSI.php');

$news = ssi_boardNews($B, 1000, null, null, 'array');

//count records
$record_count = 50;

//count max pages
$max_pages = $record_count / $per_page;

if (!$start)
    $start = 0;


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

foreach ($news as $topic)

{

echo'<a href="'.$scripturl. '?page='. $P .';Z='. $topic['message_id'] .'">'. $topic['subject'] .'</a></br>';

}
}

else {

$postID = (int) $_GET['Z'];

$output = ssi_fetchPosts($postID, false, 'array');

foreach ($output as $post)

{

echo '<h3> ' , $post['subject'] , '</h3>

<div> ' , $post['body'] , '</div>';

}
}

//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;

//show prev button
if (!($start<0))
      echo '<a href="'.$scripturl.'?page='.$P .';start='.$prev.'">Prev</a>';

//show page numbers

//set variables for first page
$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)
{
   if ($start!=$x)
      echo ' <a href="'.$scripturl.'?page='.$P .';start='.$x.'">'.$i.'</a> ';

else
      echo ' <a href="'.$scripturl.'?page='.$P .';start='.$x.'"><b>'.$i.'</b></a> ';
      $i++;
}

//show next button
if (!($start>=$record_count-$per_page))
      echo '<a href="'.$scripturl.'?page='.$P .';start='.$next.'">Next</a>';


IchBin

Wizard, you really need to work on giving people some info on what you are trying to do. Posting some code with a single sentence description does not help anyone help you very much. I couldn't figure out if you were talking about pagination for the topic listing page, or if you wanted it on the actual page that displayed the post. Either way, it is much more difficult than you can imagine probably. To do this, you would most likely have to modify the actual SMF code. Sorry, but I don't have the time to do this for you.

The Wizard

Quote from: IchBin on November 23, 2010, 06:52:44 PM
Wizard, you really need to work on giving people some info on what you are trying to do. Posting some code with a single sentence description does not help anyone help you very much. I couldn't figure out if you were talking about pagination for the topic listing page, or if you wanted it on the actual page that displayed the post. Either way, it is much more difficult than you can imagine probably. To do this, you would most likely have to modify the actual SMF code. Sorry, but I don't have the time to do this for you.

I'm sorry I was not clear. I'm trying to pagination the topic listing page.
As for it being difficult I am very aware that it is. I also know that the fact that I hardly understand PHP does not help me in this endevor, but I will still keep woking on this as my new site design requires it. I know your quite busy with the upgrades, ect..
But how is one to learn if not by trial, and error with a little help along the way. Again I'm sorry if I keep screwing up, but thats the way it is. If you want me to go way, and stop bothering people say so, but I thought this was a place to get help. Maybe I was wrong? You tell me...   

IchBin

I was just trying to tell you to give a more thorough explanation of the problem and what you're trying to achieve. Wasn't trying to tell you to leave by any means. I feel the pain on learning PHP. Taking the reigns on TP will hopefully force to me to do the same. :)

Just thinking out loud here, so hopefully it will help you think about what you can do. :) Here's the problem I see with your request. The ssi_boardNews() function returns an array(). It doesn't return anything to give you a pagination. So when you click on a pagination link, how does that function know which topics to go and get? All of the work that needs to be done to get pagination needs to be done inside that function. You have to create a way to count how many results are in the array, and then a way to identify which part of the array you want to access in order to display the next page (next set of the array). Clear as mud now? lol

The Wizard

To IchBin:

Thanks for the advice. I have come up with a script that works (Hopefully). The only problem I have now is I want the topics listed in Alphabetical order, and can't figure out how to do it from the new script. Please look over my script, and see if you can find a way to pull this off.

I think this could be done by changing the SSI.php page, but I'm not quite sure how to go about that. I know you use ORDER BY xxx ASC, and it's in the ssi_boardNews function but I'm not sure what to plug in the xxx place.

Thank You for all the help and support.

The Wizard

require_once('SSI.php');

$P = 319; // Article page that shows the captured post

$Y = 334; // Article this code has been posted too

$board = 85; // Board to get Topics from

$per_page = 10; // max displayed per page

//get start variable
$start = $_GET['start']; // =0

//count records
$record_count = mysql_num_rows (mysql_query ("SELECT * FROM OT2010_topics WHERE ID_BOARD = {$board}"));

//count max pages
$max_pages = $record_count / $per_page;

if (!$start)
   $start = 0; 

//display data
$get = mysql_query("SELECT * FROM OT2010_topics WHERE ID_BOARD = {$board} ORDER BY id_topic ASC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))

$news = ssi_boardNews($board, $per_page, null, null, 'array');

foreach($news as $topics)
{
// get data

echo'<a href="'.$scripturl. '?page='. $P .';Z='. $topics['message_id'] .'">'. $topics['subject'] .'</a></br>';

}

// set up prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;

//show prev button
if (!($start<=0))
       echo '<a href="'.$scripturl.'?page='.$Y .';start='.$prev.'">Prev</a>';

//show page numbers

//set variable for first page
$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)

{
if ($start!=$x)
      echo ' <a href="'.$scripturl.'?page='.$Y .';start='.$x.'">'.$i.'</a> ';

else
      echo ' <a href="'.$scripturl.'?page='.$Y .';start='.$x.'"><b>'.$i.'</b></a> ';
      $i++;
}

//show next button
if (!($start>=$record_count - $per_page))
        echo '<a href="'.$scripturl.'?page='.$Y .';start='.$next.'">Next</a>';


IchBin

Well, you order it by the column that has the title in the database. If you look at your database table for the topics, which field has the subject/title in it?

The Wizard

Hello:

I'm sorry but I just don't get it I have tryed dozens of combinations and I must be missing something I just don't know what. Can you lay this out for me?

IchBin

The topics table does not have the subject field in it. You have to join the messages and topic table to get all the information about a post.