Jump to content

Recommended Posts

How would I change the following to show only 30 topics then if there are more than thirty, add as many pages as needed?

 

<table style="border-top:1px #FFFFFF solid" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="3%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26"></span></td>
          <td width="54%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Subject</span></td>
          <td width="7%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Posts</span></td>
          <td width="16%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Author</span></td>
          <td width="20%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Last Post By </span></td>
        </tr>
	<?php
	$forumid = $_GET['f'];
	$topicssql = mysql_query("SELECT * FROM forum_posts WHERE topic = '0' && forumid = '{$forumid}'");
	while($topics = mysql_fetch_array($topicssql)){
	$topicid = $topics['topicid'];
	$type = $topics['type'];
	$type_img  = constant($type);
	$postssql = mysql_query("SELECT * FROM forum_posts WHERE topicid = '{$topicid}'");
	$posts = mysql_num_rows($postssql);
        echo "<tr onClick=\"MM_goToURL('parent','forum.php?t=".$topicid."');return document.MM_returnValue\" style=\"background-color:#EFF4FB;\" onMouseOver=\"this.style.backgroundColor='#E5EEF9';\" onMouseOut=\"this.style.backgroundColor='#EFF4FB';\">";
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$type_img.'</td>';
        echo '<td class="cursor_link" align="left" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$topics['title'].'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$posts.'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">OOM'.$topics['pid'].' '.$topics['name'].'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px"> </td>';
        echo '</tr>';
	}
	?>
	<tr>
	<td height="45"  colspan="2" align="left"><a href="forum.php?a=post" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('post','','../images/posthv.jpg',1)"></a><a href="forum.php?a=post"></a>
	  <table width="156" border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td align="center"><a href="forum.php?a=post"><div class="status_message status_blue">Post New Thread</div></a></td>
            </tr>
          </table></td>
	<td align="left" colspan="4"> </td>
	</tr>
      </table>

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/
Share on other sites

Kind of funny, the first result was PHP Freaks:

 

http://www.phpfreaks.com/tutorials/43/0.php

 

A lot of people seem to have trouble with that tutorial. I think there was an error in the code, they may have fixed it though, I'm not sure.

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458232
Share on other sites

What do you know, I have a fixed version of that tutorial saved on my computer from helping someone else with it.

 

<?php

$limit          = 10;
$query_count    = "SELECT count(*) FROM table";
$result_count   = mysql_query($query_count) or die("Error: " . mysql_error());
$totalrows      = mysql_result($result_count, 0, 0);
$numofpages     = ceil($totalrows/$limit);

if (isset($_GET['page'])) $page = $_GET['page'];
else $page = 1;

$offset = ($page - 1) * $limit;
$query  = "SELECT * FROM table LIMIT $offset, $limit";

echo  $query .'<br>';
$result = mysql_query($query) or die("Error: " . mysql_error());

//Exit if no records to display
if (mysql_num_rows($result) == 0) {
    exit("Nothing to Display!");
}

while ($row = mysql_fetch_array($result)) {
    echo $row['col']."</br>";
}


//Enable the Prev link if not first page
if ($page > 1) {
    echo("<a href=\"index.php?page=".($page-1)."\">PREV</a> ");
} else {
    echo("PREV ");
}

//Create links for each page in report
for ($i=1; $i<=$numofpages; $i++) {
    if ($i == $page) {
        echo "$i ";
    } else {
        echo "<a href=\"index.php?page=$i\">$i</a> ";
    }
}

//Enable the Next link if not last page
if ($page < $numofpages) {
    echo("<a href=\"index.php?page=".($page+1)."\">NEXT</a>");
} else {
    echo("NEXT");
} 

?>

 

So just replace everything in that code with your information.

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458233
Share on other sites

When I tested out the first part, it was waaaaaay off...

 

<?php
$query_count    = "SELECT count(*) FROM forum_posts WHERE topic = '0'";
	$result_count   = mysql_query($query_count) or die("Error: " . mysql_error());
	$totalrows      = mysql_result($result_count, 0, 0);
	$numofpages     = ceil($totalrows/$limit);
	echo $numofpages;
?>

 

And it echoed 11, when the limit is 30 and there are 2 threads.

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458239
Share on other sites

I get the following error...

 

1Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1

 

<table style="border-top:1px #FFFFFF solid" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="3%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26"></span></td>
          <td width="54%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Subject</span></td>
          <td width="7%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Posts</span></td>
          <td width="16%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Author</span></td>
          <td width="20%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Last Post By </span></td>
        </tr>
	<?php
	$forumid = $_GET['f'];
	$topicssql = mysql_query("SELECT * FROM forum_posts WHERE topic = '0' && forumid = '{$forumid}'");
	while($topics = mysql_fetch_array($topicssql)){
	$topicid = $topics['topicid'];
	$type = $topics['type'];
	$type_img  = constant($type);

	$query_count    = "SELECT count(*) FROM forum_posts WHERE topic = '0'";
	$result_count   = mysql_query($query_count) or die("Error: " . mysql_error());
	$totalrows      = mysql_result($result_count, 0, 0);
	$numofpages     = ceil($totalrows/$limit);
	echo $numofpages;
	if (isset($_GET['page'])){ $page = $_GET['page'];}
else{ $page = 1;}

$offset = ($page - 1) * $limit;
$query = mysql_query("SELECT * FROM forum_posts WHERE topicid = '{$topicid}' LIMIT $offset, $limit");
$result = mysql_query($query) or die("Error: " . mysql_error());
if (mysql_num_rows($result) == 0) {
    exit("Nothing to Display!");
}


	$postssql = mysql_query("SELECT * FROM forum_posts WHERE topicid = '{$topicid}'");
	$posts = mysql_num_rows($query);
        echo "<tr onClick=\"MM_goToURL('parent','forum.php?t=".$topicid."');return document.MM_returnValue\" style=\"background-color:#EFF4FB;\" onMouseOver=\"this.style.backgroundColor='#E5EEF9';\" onMouseOut=\"this.style.backgroundColor='#EFF4FB';\">";
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$type_img.'</td>';
        echo '<td class="cursor_link" align="left" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$topics['title'].'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$posts.'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">OOM'.$topics['pid'].' '.$topics['name'].'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px"> </td>';
        echo '</tr>';
	}
	if ($page > 1) {
    echo("<a href=\"forum.php?page=".($page-1)."\">PREV</a> ");
} else {
    echo("PREV ");
}
for ($i=1; $i<=$numofpages; $i++) {
    if ($i == $page) {
        echo "$i ";
    } else {
        echo "<a href=\"forum.php?page=$i\">$i</a> ";
    }
}
if ($page < $numofpages) {
    echo("<a href=\"forum.php?page=".($page+1)."\">NEXT</a>");
} else {
    echo("NEXT");
} 
	?>
	<tr>
	<td height="45"  colspan="2" align="left"><a href="forum.php?a=post" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('post','','../images/posthv.jpg',1)"></a><a href="forum.php?a=post"></a>
	  <table width="156" border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td align="center"><a href="forum.php?a=post"><div class="status_message status_blue">Post New Thread</div></a></td>
            </tr>
          </table></td>
	<td align="left" colspan="4"> </td>
	</tr>
      </table>

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458257
Share on other sites

Okay, well you have a ton of queries in there and we have no idea which query is getting that error. In the error message for all your queries you need to number them. Instead of just saying "Error", you should put "Error 1" for the first query and so on.

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458263
Share on other sites

$query = mysql_query("SELECT * FROM forum_posts WHERE topicid = '{$topicid}' LIMIT $offset, $limit");
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error());

 

Error (QUERY): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6' at line 1

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458267
Share on other sites

I changed it to:

<?php
$query = mysql_query("SELECT * FROM forum_posts WHERE topicid = '{$topicid}' LIMIT '{$offset}', '{$limit}'");
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error());
?>

 

and it gives the error:

 

Error (QUERY): Query was empty

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458269
Share on other sites

Your running mysql_query() twice. It should be

 

<?php
$query = "SELECT * FROM forum_posts WHERE topicid = '$topicid' LIMIT '$offset', '$limit'";
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error());
?>

 

I also don't see a need for the brackets around all the variables.

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458278
Share on other sites

It should be a lot more than 4 characters shorter if you changed everything I did. Did you actually copy and paste the code?

 

Even better, copy and paste this then copy and paste what it says:

 

<?php
$query = "SELECT * FROM forum_posts WHERE topicid = '$topicid' LIMIT '$offset', '$limit'";
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error() . "<p>With Query:<br>$query<p>");
?>

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458288
Share on other sites

Well, That helped a lot (no sarcasm)...

 

It is now giving a detailed error:

 

Error (QUERY): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0', '30'' at line 1

 

With Query:

SELECT * FROM forum_posts WHERE topicid = '1' LIMIT '0', '30'

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458291
Share on other sites

Oh, duh...you need to get rid of the single quotes in the LIMIT part.

 

<?php
$query = "SELECT * FROM forum_posts WHERE topicid = '$topicid' LIMIT $offset, $limit";
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error() . "<p>With Query:<br>$query<p>");
?>

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458294
Share on other sites

And now it echo's 'Nothing to Display'

 

<?php
$query_count    = "SELECT count(*) FROM forum_posts WHERE topic = '0'";
	$result_count   = mysql_query($query_count) or die("Error: (result_count) " . mysql_error());
	$totalrows      = mysql_result($result_count, 0, 0);
	$numofpages     = ceil($totalrows/$limit);
	if (isset($_GET['page'])){ $page = $_GET['page'];}
else{ $page = 1;}

$offset = ($page - 1) * $limit;
$query = "SELECT * FROM forum_posts WHERE topicid = '$topicid' LIMIT $offset,$limit";
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error() . "<p>With Query:<br>$query<p>");
if (mysql_num_rows($result) == 0) {
    exit("Nothing to Display!");
}
  ?>
  
  <table style="border-top:1px #FFFFFF solid" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="3%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26"></span></td>
          <td width="54%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Subject</span></td>
          <td width="7%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Posts</span></td>
          <td width="16%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Author</span></td>
          <td width="20%" height="20" align="center" valign="middle" bgcolor="#333355"><span class="style26">Last Post By </span></td>
        </tr>
	<?php
	$forumid = $_GET['f'];
	$topicssql = mysql_query("SELECT * FROM forum_posts WHERE topic = '0' && forumid = '{$forumid}'") or die("Error (TOPICSSQL): " . mysql_error());;
	while($topics = mysql_fetch_array($result)){
	$topicid = $topics['topicid'];
	$type = $topics['type'];
	$type_img  = constant($type);


	$postssql = mysql_query("SELECT * FROM forum_posts WHERE topicid = '{$topicid}'") or die("Error ($POSTSQL): " . mysql_error());;
	$posts = mysql_num_rows($query);
        echo "<tr onClick=\"MM_goToURL('parent','forum.php?t=".$topicid."');return document.MM_returnValue\" style=\"background-color:#EFF4FB;\" onMouseOver=\"this.style.backgroundColor='#E5EEF9';\" onMouseOut=\"this.style.backgroundColor='#EFF4FB';\">";
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$type_img.'</td>';
        echo '<td class="cursor_link" align="left" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$topics['title'].'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">'.$posts.'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px">OOM'.$topics['pid'].' '.$topics['name'].'</td>';
        echo '<td class="cursor_link" align="center" valign="middle" style="border-bottom:1px #333355 solid" height="50px"> </td>';
        echo '</tr>';
	}
	if ($page > 1) {
    echo("<a href=\"forum.php?f=".$_GET['f']."&page=".($page-1)."\">PREV</a> ");
} else {
    echo("PREV ");
}
for ($i=1; $i<=$numofpages; $i++) {
    if ($i == $page) {
        echo "$i ";
    } else {
        echo "<a href=\"forum.php?f=".$_GET['f']."&page=$i\">$i</a> ";
    }
}
if ($page < $numofpages) {
    echo("<a href=\"forum.php?f=".$_GET['f']."&page=".($page+1)."\">NEXT</a>");
} else {
    echo("NEXT");
} 
	?>
	<tr>
	<td height="45"  colspan="2" align="left">
	<?php
	if($logged_in){
	?>
	  <table width="156" border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td align="center"><a href="forum.php?a=post"><div class="status_message status_blue">Post New Thread</div></a></td>
            </tr>
          </table>
	  <?php
	  }
	  ?></td>
	<td align="left" colspan="4"> </td>
	</tr>
      </table>

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458302
Share on other sites

$query = "SELECT * FROM forum_posts WHERE topicid = '0' && forumid = '{$forumid}' LIMIT $offset,$limit";
$result = mysql_query($query) or die("Error (QUERY): " . mysql_error() . "<p>With Query:<br>$query<p>");

 

But nothing displays...

 

capture8.jpg

Link to comment
https://forums.phpfreaks.com/topic/89474-solved-forum-limit-30/#findComment-458324
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.