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

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

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

wappy
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:


page 2:


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:


page2:


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

part 1:
CODE
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&amp;name=$enc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=old&amp;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&amp;name=$enc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=old&amp;page=1\">$image$rowas[1](".$postu[0].")</a>"; echo "<br/>";

}

echo "<br/>";

} else echo "Your Banned!";

}


part2:
CODE
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&amp;id=$id&amp;nick=$nick&amp;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&amp;id=$id&amp;nick=$nick&amp;pass=$pass&amp;page=$page\">Next</a><br/>";

$page=$page-2;

if ($page>0) echo "<a href=\"index.php?action=viewforum&amp;id=$id&amp;nick=$nick&amp;pass=$pass&amp;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&amp;nick=$nick&amp;pass=$pass&amp;page=1\">Inbox$unrd</a><br/>";

}}

echo "Page: $page/$poststot<br/>";

echo "<a href=\"index.php?action=newthread&amp;id=$id&amp;nick=$nick&amp;pass=$pass\">New Topic</a>";

echo "<br/><a href=\"index.php?nick=$nick&amp;pass=$pass\">Home</a>";

} else echo "Viewing impossible!<br/><a href=\"index.php?nick=$nick&amp;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 ;-)

 

 

 


Reply

galexcd
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:
CODE
$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:

CODE
$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 smile.gif

 

 

 


Reply

wappy
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 ;-)

Reply

galexcd
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:
CODE
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&amp;name=$enc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=old&amp;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?

Reply

wappy
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://wapforums.us 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 ;-) ;-)

Reply

jlhaslip
Topic is resolved.

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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : php pages resolved im stuck

  1. Protect Pages - HOW? (20)
    I create certain pages for my web-site, and I would like to protect them that no one can hack or see
    their source codes. So, if everybody knows how to do it, please post a reply over here. List of
    the best ways, I can do it. Thanks....
  2. Dynamic Php Pages - Nice tutorial (5)
    This is a really good tutorial on making php pages that normally appear as
    www.domainname.com/links.php appear as www.domainname.com/index.php?page=links
    http://nuwen.com/tutorials/php-dynamic-pages ...
  3. Pagination - ? (3)
  4. 2 Pages Into One - how? (10)
    Hello, now this may be a stupid question but i'm very new to php so i need some help. what
    i'm wanting to do is combine 2 pages in to one. like for example the install.php for
    invisionpower board it starts with one page and you click continue and it gives you a whole new page
    but if you look at the url you are still using the install.php file but it has somethinglike "?a=2"
    at the end. how can i do this. Thanks...
  5. Php An Js Window.open Pages Trouble. - I need a way to set hidden input values to the new window. (3)
    I have 2 main pages Page A(events_locked.php) and Page B(add_attendance.php). Both are php files.
    Page A takes a post var from another page(not Page B ) and then used to query for displaying records
    in a mysql datase. This variable has set as a session variable because there is 1 <script
    LANGUAGE="JavaScript"> window.name="main_index"; function openFormWindow() {
    OpenWindow=window.open("add_attendance.php", "newwin", "height=250,
    width=400,toolbar=no,scrollbars=no,menubar=no,location=no,resizable=no"); var x =
    getElementByName("form1"); x.target="newwin"; x.s...
  6. Php Pages Permission On Apache Server - PHP pages permission on Apache Server (1)
    Hello, I want to know what permissions for PHP pages should be given on Apache web server so that
    PHP pages can be executed. If PHP pages are in a folder, what permissions should be given for that
    folder? ...
  7. Putting Data Of 2 Pages In Mysql At Once - (1)
    suppose i have a page, page.php?part=1 there i have some text fields. user will give input, but
    after taking input, it will not put the data in mysql .. but it will take to the next step..
    page.php?part=2 (if any field is left blank, it will not go to next page.. ) . and there also some
    fields.. after the user has filled that form also, then it will insert all data (from part1 and
    part 2) in mysql. i want to ask, how i can collect data from 2 pages and put in mysql at once....
  8. Search Site Pages Using Keywords? - (6)
    We're doing a "Mock" e-commerce site for our project in Web Development and I was wondering how
    to make a Search form like the ones in many sites. There will be a Search textbox and a button in
    the form which will accept a string (keywords) which will then be processed by a script. If there
    is a match, a page containg the keywords will be displayed. Is there a way to do this using PHP or
    is there an existing free script out there already? Thanks very much....
  9. Changing Include Tag On All Pages - (11)
    I want to change an include tag (include menu.htm) to include menu.php on all my pages on my
    website. Is there any fast way to do this, or do I have to edit all of my pages manually?
    /unsure.gif' border='0' style='vertical-align:middle' alt='unsure.gif' /> ...
  10. Parsing .html Pages - (9)
    This isn't really that urgent but I was wondering, I read somewhere that you can configure you
    server to pars all html pages for php code, and I was wondering if that was true, and if trap17 has
    that feature enabled?...
  11. Blocking Pages & Making Ranks - (4)
    I would like to know how and where to put the code that would block certain pages so people could
    only get to them if they logged in. And I would like to have ranks on the site and when you get to a
    certain rank you get more options like being able to add members and stuff. And also. I would like
    some code for a news sytem for the homepage. Like where you have to be logged in to post something
    and only people with certain ranks will have access to it and only certain people can delete it. I
    would like to be able to make it so on the members page it displays members and y...
  12. Securing Pages - (2)
    just wondering if there is a easy safe way to secure some webpages. i have a payment facility on my
    site which is linked through paypal. when the member has paid they are taken back to my site "thanks
    your payment has been successful page", once its went to this page the item is no longer listed on
    my site. now i have found away people can mess with this using the url. this means people can
    change just a few digits in the url and and mess the listings up on my site. after payment has been
    made the member is redirected to:- mydomain.com/class/thanks_paypal.php?myprod_...
  13. Php Classes - Access the same class instance over multiple pages (1)
    Hey everyone. I am having some trouble accessing the same php class instance in more that one page.
    This is for my login script and what i need to do is be able to call the classes logout function
    from a separate page. What i have tried to do is create a new .php page and include the class file
    and then make a new class and call logout. This does not work because it does not log out the
    current user which is my problem. Can anyone help me fix this or know of another way to do it?
    Below is my class file CODE <?php     // member class     // handlers member logo...
  14. Pages In 1 File - ?? (9)
    I know its possible to put many pages inside 1 file. But how? Lets say you have a guestbook with
    different pages for signing and viewing. How to make so those pages are in 1 file? /huh.gif"
    style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" />...
  15. Embeding Pages - (3)
    Is there a way to have php act as an iframe? I dont want to have to change every single page when i
    want to move something around. If anyone can give me a tutorial or somethign telling me how that
    would be great, or ven another way of doing this without frames....



Looking for php, pages, problem, im, stuck,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for php, pages, problem, im, stuck,

*MORE FROM TRAP17.COM*
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE