Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,544,674
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-06-24 06:04 AM
Guest: Register | Login

0 users currently in Computing | 4 guests

Main - Computing - PHP: Link to a post New thread | New reply


Pac
Posted on 06-26-07 05:15 PM (rev. 3 of 06-26-07 09:33 PM) Link | Quote | ID: 49775


Flurry
Level: 37

Posts: 135/262
EXP: 336224
Next: 2029

Since: 02-19-07
From: Japan

Last post: 4484 days
Last view: 2886 days
Okay so I'm building a message board from scratch, and I'm just finishing off the final features, but I'm having a little problem with the Link link on posts; in that it takes about four or five seconds to actually find the post. Here's the code:


if($pid){

$post=mysql_fetch_array(mysql_query("SELECT thread FROM posts WHERE id='$pid'"));
$threadid=$post[thread];

$getposts=mysql_query("SELECT id FROM posts WHERE thread='$threadid' ORDER BY date");
while($post=mysql_fetch_array($getposts)){

$postno++;

if($post['id']==$pid){

$gotopage=floor(($postno-1)/$ppp)+1;
header("Location: thread.php?id=$threadid&page=$gotopage#$pid");

}
}
}


The code scans through all of the posts in a thread to find what page the post is on. Is there any more efficient way of doing this? Thanks.

stag019
Posted on 06-26-07 05:18 PM Link | Quote | ID: 49777


Snifit
Level: 40

Posts: 148/299
EXP: 409915
Next: 31394

Since: 02-19-07

Last post: 4290 days
Last view: 2176 days
	if($pid)
{
if(!$ppp) $ppp=($log?$loguser[postsperpage]:20);
$id = mysql_result(mysql_query("SELECT `thread` FROM `posts` WHERE `id` = '$pid'"), 0);
$numposts = mysql_result(mysql_query("SELECT COUNT(*) FROM `posts` WHERE `thread` = '$id' AND `id` < '$pid'"), 0);
$page = floor($numposts / $ppp);
if (!$r)
{
header("Location: thread.php?pid=$pid&r=1#$pid");
die();
}
}
Xkeeper's old code from Inc. 3, which he posted in the announcements.

OoBurns
Posted on 06-26-07 09:29 PM Link | Quote | ID: 49850


Boo
Level: 68

Posts: 782/1036
EXP: 2643629
Next: 85171

Since: 02-19-07
From: It is a mystery.

Last post: 5732 days
Last view: 5732 days
Did anyone else immediately think of A Link to the Past when they saw this thread?

____________________

Pac
Posted on 06-26-07 09:32 PM Link | Quote | ID: 49852


Flurry
Level: 37

Posts: 138/262
EXP: 336224
Next: 2029

Since: 02-19-07
From: Japan

Last post: 4484 days
Last view: 2886 days
I did after I made it, and then I kicked myself for not making it more... funny

Xkeeper
Posted on 06-26-07 09:34 PM (rev. 2 of 06-26-07 09:36 PM) Link | Quote | ID: 49853


Level: 105

Posts: 2341/2846
EXP: 12037627
Next: 224633

Since: 02-19-07

Last post: 6070 days
Last view: 2807 days
  elseif($pid=$_GET[pid]){
    checknumeric($pid);
    $tid =$sql->resultq("SELECT thread FROM posts WHERE id=$pid");
    $page=floor($sql->resultq("SELECT COUNT(*) FROM posts WHERE thread=$tid AND id<$pid")/$loguser[ppp])+1;
  }


Hasn't changed much, really.

____________________
I dealt with it.

Pac
Posted on 06-27-07 05:11 AM Link | Quote | ID: 49986


Flurry
Level: 37

Posts: 139/262
EXP: 336224
Next: 2029

Since: 02-19-07
From: Japan

Last post: 4484 days
Last view: 2886 days
Alright, thanks for the help

Main - Computing - PHP: Link to a post New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.021 seconds. (321KB of memory used)
MySQL - queries: 52, rows: 66/67, time: 0.017 seconds.