Jump to content
xisto Community
Sign in to follow this  
wappy

Php Pages Problem [resolved] Please help me im stuck ;-(

Recommended Posts

Hi, i have been working with a wap forum script, translating from russian and fixing errors etc.. but now im stuck, the problem is with the pages while viewing a forum..

 

Let me explain.. the pages are set to show ten topics per page which all works fine as you can see in these screenshots:

 

page 1:

Posted Image

 

page 2:

Posted Image

 

The problem occurs when there are PINNED topics (with the redish folder), it will show ten topics but also the pinned ones on page one, and the "Next" link will appear before it should leading to a blank page where there should be topics but they are still on the other page lol..

 

Here is a screenshot of the pages not working with pinned topics..

 

page1:

Posted Image

 

page2:

Posted Image

 

Now here is the two bits of code relating to it:

 

part 1:

function getposts($id,$nick,$pass,$page){slogin($nick,$pass);global $banned;//  $letssee=false;if (!$banned) {$page=$page-1;if (!$page==0) $page=$page*10; else $page=0;$pagemore=$page+10;$pinnedposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='1' ORDER BY position LIMIT ".$page.",5");$kiekpinnintu=mysql_num_rows($pinnedposts);$ikipage=10-$kiekpinnintu;if ($ikipage<0) $ikipage=0;$userposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='0' ORDER BY position LIMIT ".$page.",10");echo "<br/>";while ($rowas = mysql_fetch_array($pinnedposts)){$isclosed=mysql_fetch_array(mysql_query("SELECT closed FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));$postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$id."' AND name='".$rowas[1]."'"));$rowas[1]=htmlspecialchars($rowas[1]);$enc=urlencode($rowas[1]);$enc=htmlspecialchars($enc);$image="<img src=\"images/pinned.gif\" alt=\"*\"/>";if ($isclosed[0]==1) {$image="<img src=\"images/closed.gif\" alt=\"*\"/>";}echo "<a href=\"index.php?action=viewpost&name=$enc&nick=$nick&pass=$pass&forumas=$id&read=old&page=1\">$image$rowas[1](".$postu[0].")</a>"; echo "<br/>";}while ($rowas = mysql_fetch_array($userposts)){$isclosed=mysql_fetch_array(mysql_query("SELECT closed FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));$postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$id."' AND name='".$rowas[1]."'"));$rowas[1]=htmlspecialchars($rowas[1]);$enc=urlencode($rowas[1]);$enc=htmlspecialchars($enc);//$viewpost_title =convert_cyr_string($rowas[1],"i","w");if ($postu[0]>20) {$image="<img src=\"images/hot.gif\" alt=\"*\"/>";} else {$image="<img src=\"images/normal.gif\" alt=\"*\"/>";}if ($isclosed[0]==1) {$image="<img src=\"images/closed.gif\" alt=\"*\"/>";}echo "<a href=\"index.php?action=viewpost&name=$enc&nick=$nick&pass=$pass&forumas=$id&read=old&page=1\">$image$rowas[1](".$postu[0].")</a>"; echo "<br/>";}echo "<br/>";} else echo "Your Banned!";}

part2:

if ($action=="viewforum")		   {							 //let's have a look @ forum$forumnameasasas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$id."'"));echo "<card id=\"viewforum\" title=\"$forumnameasasas[0]\">";echo "<p align=\"center\">";global $timezone;$valandos=date("H")+$timezone;if ($valandos>23) $valandos=$valandos-24;$data=date("y m d - ".$valandos.":i");echo "$data<br/>";echo ismod($nick,$pass,$id);global $moderator;if ($moderator) echo "Welcome Moderator!<br/>";$letssee=false;$fperms=mysql_fetch_array(mysql_query("SELECT perms FROM forums WHERE id='".$id."'"));if ($fperms[0]=="0") {$letssee=true;}if ($fperms[0]=="1") {$letssee=true;}if ($fperms[0]=="2") {$forribdforums=mysql_query("SELECT forum FROM permissions WHERE name='".$nick."'");while ($frumas=mysql_fetch_array($forribdforums)) {if ($frumas[0]==$id or $frumas[0]=="*") {$letssee=true;}}}if ($letssee) {echo "<a href=\"index.php?action=newthread&id=$id&nick=$nick&pass=$pass\">New Topic</a>";//echo "<br/>";echo "</p><p align=\"left\">";echo getposts($id,$nick,$pass,$page);echo "</p><p align=\"center\">";$page=$page+1;$poststot=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$id."' AND thread='1'"));$poststot[0]=$poststot[0];//echo "<br/>";$poststot=ceil($poststot[0]/10);if ($page<$poststot+1) echo "<a href=\"index.php?action=viewforum&id=$id&nick=$nick&pass=$pass&page=$page\">Next</a><br/>";$page=$page-2;if ($page>0) echo "<a href=\"index.php?action=viewforum&id=$id&nick=$nick&pass=$pass&page=$page\">Prev</a><br/>";$page=$page+1;if ($poststot==0) $poststot=1;echo slogin($nick,$pass);global $logged;if ($logged) {$unreadinbox=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM private WHERE unread='y' AND sentto='".$nick."'"));if ($unreadinbox[0]>0) {$pmtotl=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM private WHERE sentto='".strtolower($nick)."'"));$unrd="(".$unreadinbox[0]."/".$pmtotl[0].")";echo "<a href=\"index.php?action=private&nick=$nick&pass=$pass&page=1\">Inbox$unrd</a><br/>";}}echo "Page: $page/$poststot<br/>";echo "<a href=\"index.php?action=newthread&id=$id&nick=$nick&pass=$pass\">New Topic</a>";echo "<br/><a href=\"index.php?nick=$nick&pass=$pass\">Home</a>";} else echo "Viewing impossible!<br/><a href=\"index.php?nick=$nick&pass=$pass\">Home</a>";echo "</p>";echo "</card>";}

Any help with this woll be much appreciated as its the last error on the script, then it will be 100% working ;-) thanks ;-)
Edited by wappy (see edit history)

Share this post


Link to post
Share on other sites

Alright I'll make this brief. You can fix this by checking how many pinned topics you have and subtracting that from the limit of your regular query but this in my opinion would just make your life harder. This is what I would do: Instead of having 2 sql queries (one for the pinned threads and one without), only have one and order it by pinned, and then position.

So instead of this:

$pinnedposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='1' ORDER BY position LIMIT ".$page.",5");[...]$userposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='0' ORDER BY position LIMIT ".$page.",10");

Do this:

$userposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' ORDER BY  pinned DESC, position ASC LIMIT ".$page.",10");

Hope this helps :)
Edited by alex7h3pr0gr4m3r (see edit history)

Share this post


Link to post
Share on other sites

Yes i think i understand, i didn't write this script just translating/fixing/updating but i think what they have tried to do is the second method you describe, as the amount of pages are worked out right but not the limit, if you could can you please give an example of doing it that way and also tell me why it will make things harder?? Thanks a lot for the help ;-)

Share this post


Link to post
Share on other sites

Well I guess since the code is already written out that way it won't be harder but it sure is a waist of code.

Here is how I would do it:

function getposts($id,$nick,$pass,$page){slogin($nick,$pass);global $banned;//  $letssee=false;if (!$banned) {$page=$page-1;if (!$page==0) $page=$page*10; else $page=0;$pagemore=$page+10;$userposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' ORDER BY  pinned DESC, position ASC LIMIT ".$page.",10");echo "<br/>";while ($rowas = mysql_fetch_array($userposts)){$isclosed=mysql_fetch_array(mysql_query("SELECT closed FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));$ispinned=mysql_fetch_array(mysql_query("SELECT pinned FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));$postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$id."' AND name='".$rowas[1]."'"));$rowas[1]=htmlspecialchars($rowas[1]);$enc=urlencode($rowas[1]);$enc=htmlspecialchars($enc);//$viewpost_title =convert_cyr_string($rowas[1],"i","w");if($ispinned[0]==1)$image="<img src=\"images/pinned.gif\" alt=\"*\"/>";else if($postu[0]>20) $image="<img src=\"images/hot.gif\" alt=\"*\"/>";else $image="<img src=\"images/normal.gif\" alt=\"*\"/>";if ($isclosed[0]==1)$image="<img src=\"images/closed.gif\" alt=\"*\"/>";echo "<a href=\"index.php?action=viewpost&name=$enc&nick=$nick&pass=$pass&forumas=$id&read=old&page=1\">$image$rowas[1](".$postu[0].")</a>"; echo "<br/>";}echo "<br/>";} else echo "Your Banned!";}

Just a quick note I don't have time to read through every single line so there might be something I forgot to do when changing this for you, but if you know enough php to be rewriting forums you should get the gist of what I'm trying to do here.

And what's with this code and having a random new line after every line of code?

Share this post


Link to post
Share on other sites

Thanks, with all this im very sure i can work it out.. as for the lines etc.. as i say i didn't write this.. if you want to look at the site im testing on go to http://forums.xisto.com/no_longer_exists/ with a mobile phone, opera, or the wml plugin for firefox..

the code is a bit of a mess but im sure on viewing the site you will see why im working with it... ;-)thanks again ;-)

EDIT: works perfect, many many thanks ;-) ;-)

Edited by wappy (see edit history)

Share this post


Link to post
Share on other sites

Topic is resolved.Please PM any moderator to continue this discussion. Until then, this topic is closed.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.