noobstar Posted December 6, 2006 Share Posted December 6, 2006 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/ Share on other sites More sharing options...
noobstar Posted December 6, 2006 Author Share Posted December 6, 2006 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 numberif(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 numberswhile($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 oneif ($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 pageif ($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 linkecho $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-135950 Share on other sites More sharing options...
JasonLewis Posted December 6, 2006 Share Posted December 6, 2006 well that looks all good but what does posts.php look like? because it may be something to do with how you are using the gathered information there. Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-135963 Share on other sites More sharing options...
noobstar Posted December 6, 2006 Author Share Posted December 6, 2006 If posts.php didn't work then it wouldn't have worked for the 2nd page link but it did ... Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-135973 Share on other sites More sharing options...
JasonLewis Posted December 6, 2006 Share Posted December 6, 2006 well it basicly has to be. unless$row['thread_id'] is blank or null for the first thread. but i dont no. if its not that then it has to be something in the posts.php Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-135977 Share on other sites More sharing options...
noobstar Posted December 6, 2006 Author Share Posted December 6, 2006 When ever i press on one of the links i get this error i hope this helps:[img]http://img84.imageshack.us/img84/9573/errorgo7.jpg[/img] Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136021 Share on other sites More sharing options...
JasonLewis Posted December 6, 2006 Share Posted December 6, 2006 that error is javascript. my knowledge isnt that brilliant. why do you have to use forms for this? do you want to hide the data or something? Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136025 Share on other sites More sharing options...
noobstar Posted December 6, 2006 Author Share Posted December 6, 2006 This is simply the thing im tring to do:Each query pulled out has ...forum iduserfieldthread idsubject(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. Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136026 Share on other sites More sharing options...
noobstar Posted December 6, 2006 Author Share Posted December 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136043 Share on other sites More sharing options...
JasonLewis Posted December 7, 2006 Share Posted December 7, 2006 i am still querying, why do you have to use forms for this? cant you just use $_GET values. Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136703 Share on other sites More sharing options...
noobstar Posted December 7, 2006 Author Share Posted December 7, 2006 Never mind i solved it thank you again for the support though :) Quote Link to comment https://forums.phpfreaks.com/topic/29627-paged-query-issues/#findComment-136756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.