Jump to content

Recommended Posts

I have a problem with my paged query code the error is mainly in a submit link based button that i added here is the area:

[code] echo "<table width=700 border=0>";
echo "<tr><td valign='middle' align='center' bgcolor=#58a7c6>";
            //This is the bit that fails for the first page but works for the 2nd
echo "<form name='posts' method=post action='posts.php' style='display:inline'>";
echo "<a href='javascript:document.posts.submit();'>".$row['subject']."</a>";
echo "<input type=hidden name=thread_id value=".$row['thread_id'].">";
echo "<input type=hidden name=subject value='".$row['subject']."'>";
echo "<input type=hidden name=forum_id value=".$forum_id.">";
echo "<input type=hidden name=username value=".$username.">";
echo "</form>";
echo "</td><tr/></table>";[/code]

The problem is when i run this script it displays the first 5 queries then has links on the bottom to go to the next page and so forth. I have tried creating a link of the subject name with the above code it works for the 2nd page that gets displayed but it does not work for the first page.

In other words when someone clicks on the subject name "This is a test" it would go to another page and display posts etc. As i mentioned above it works for the 2nd page but not for the first one :(

If you have any ideas or suggestions please let me know.

Thank you for any replies :)
Link to comment
https://forums.phpfreaks.com/topic/29627-paged-query-issues/
Share on other sites

Here is the full source code: (I had to remove the mysql_connect & mysql_select_db connections there wasnt much space)
[code]<?php
// how many rows to show per page
$rowsPerPage = 5;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$query  = "SELECT * FROM forum_threads where forum_id='$forum_id' LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

// print the random numbers
while($row = mysql_fetch_array($result))
{
echo "<table width=700 border=0>";
echo "<tr><td valign='middle' align='center' bgcolor=#58a7c6>";
echo "<form name='posts' method=post action='posts.php' style='display:inline'>";
echo "<a href='javascript:document.posts.submit();'>".$row['subject']."</a>";
echo "<input type=hidden name=thread_id value=".$row['thread_id'].">";
echo "<input type=hidden name=subject value='".$row['subject']."'>";
echo "<input type=hidden name=forum_id value=".$forum_id.">";
echo "<input type=hidden name=username value=".$username.">";
echo "</form>";
echo "</td><tr/></table>";
}

echo '<br>';

// how many rows we have in database
$query  = "SELECT COUNT(subject) AS numrows FROM forum_threads where forum_id='$forum_id'";
$result  = mysql_query($query) or die('Error, query failed');
$row    = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

// creating 'previous' and 'next' link
// plus 'first page' and 'last page' link

// print 'previous' link only if we're not
// on page one
if ($pageNum > 1)
{
    $page = $pageNum - 1;
    $prev = "<form method=post action=\"$self?page=$page\" style=display:inline><input type=hidden name=forum_id value=".$forum_id."><input type=submit value=[Prev]></form>";
   
    $first = "<form method=post action=\"$self?page=1\" style=display:inline><input type=hidden name=forum_id value=".$forum_id."><input type=submit value='[First Page]'></form>";
}
else
{
    $prev  = ' [Prev] ';      // we're on page one, don't enable 'previous' link
    $first = ' [First Page] '; // nor 'first page' link
}

// print 'next' link only if we're not
// on the last page
if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = "<form method=post action=\"$self?page=$page\" style=display:inline><input type=hidden name=forum_id value=".$forum_id."><input type=submit value=[Next]></form>";
   
    $last = "<form method=post action=\"$self?page=$maxPage\" style=display:inline><input type=hidden name=forum_id value=".$forum_id."><input type=submit value='[Last Page]'></form>";
}
else
{
    $next = ' [Next] ';      // we're on the last page, don't enable 'next' link
    $last = ' [Last Page] '; // nor 'last page' link
}

// print the page navigation link
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-135950
Share on other sites

This is simply the thing im tring to do:

Each query pulled out has ...

forum id
userfield
thread id
subject

(they are all inside hidden textfields)

... attached to it so when someone clicks on the link the values are send to posts and then they are used there and when the user clicks back from posts to go back into threads forum id & userfield are posted back thats pretty much it. Just as a note not sure if that helps is userfield is empty until the user logs in but it is still posted to and from the threads script.
Link to comment
https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136026
Share on other sites

I discoverd the root of the problem ok this is what i did. I created a 2nd thread on the 2nd page (there were 6 threads to start with 5 on the first page and 1 on the 2nd page). When i added the 2nd thread the only one working thread link stopped working.

I know this answers nothing but adds more questions lol
Link to comment
https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136043
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.