Welcome to Geeklog, Anonymous Thursday, December 26 2024 @ 09:54 am EST
Geeklog Forums
Staticpages/PHP/phpbb
Status: offline
eyecravedvd
Forum User
Full Member
Registered: 06/09/03
Posts: 152
I've created the following code in lib-custom.php and am trying to call it through echo getPosts(); in staticpages. I had the code in the staticpage and was getting the same result, which is visible on this page here
function getPosts() {
global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT $count";
if($row = mysql_query($sql)) {
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
}
$display .= '<tr><td width="50%" style="font-weight: bold;"><a title="$topic" href="$forum_url/viewtopic.php?p=$post">$topic</a></td>';
$display .= '<td width="20%">$user</td>';
$display .= '<td width="20%">$forum</td>';
$display .= '<td width="10%">$replies</td></tr>';
}
$display .= '</table>';
return $display;
}
Shane | www.EyeCraveDVD.com
Text Formatted Code
function getPosts() {
global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT $count";
if($row = mysql_query($sql)) {
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
}
$display .= '<tr><td width="50%" style="font-weight: bold;"><a title="$topic" href="$forum_url/viewtopic.php?p=$post">$topic</a></td>';
$display .= '<td width="20%">$user</td>';
$display .= '<td width="20%">$forum</td>';
$display .= '<td width="10%">$replies</td></tr>';
}
$display .= '</table>';
return $display;
}
Shane | www.EyeCraveDVD.com
12
8
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Text Formatted Code
function getPosts() {global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT $count";
if($row = mysql_query($sql)) {
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
}
$display .= '<tr><td width="50%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$display .= '<td width="20%">' . $user . '</td>';
$display .= '<td width="20%">' . $forum . '</td>';
$display .= '<td width="10%">' . $replies . '</td></tr>';
}
$display .= '</table>';
return $display;
}
try that. and you may want to check that url you posted... extra http
12
10
Quote
Status: offline
eyecravedvd
Forum User
Full Member
Registered: 06/09/03
Posts: 152
Thanks machinari. Only one problem now. It only shows one result when there are 3 posts. Any ideas?
Shane | www.EyeCraveDVD.com
Shane | www.EyeCraveDVD.com
8
10
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
maybe do the same thing i did with your post vars in the html with your $count in the sql statement var. that should do it.
like this:
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT" . $count;
like this:
Text Formatted Code
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT" . $count;
9
10
Quote
Status: offline
eyecravedvd
Forum User
Full Member
Registered: 06/09/03
Posts: 152
I tried just putting the number right in there and I still get the same results.
I ran the SQL query through phpMyAdmin and it works. It calls all the results fine.
Shane | www.EyeCraveDVD.com
I ran the SQL query through phpMyAdmin and it works. It calls all the results fine.
Shane | www.EyeCraveDVD.com
7
10
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
you need to rearrange your while statement so it loops thru the content, not the headings.
try this:
global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT" . $count;
//table headings
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
if($row = mysql_query($sql)) {
//table content
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$display .= '<tr><td width="50%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$display .= '<td width="20%">' . $user . '</td>';
$display .= '<td width="20%">' . $forum . '</td>';
$display .= '<td width="10%">' . $replies . '</td></tr>';
}
}
$display .= '</table>';
return $display;
}
try this:
Text Formatted Code
function getPosts() {global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT" . $count;
//table headings
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
if($row = mysql_query($sql)) {
//table content
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$display .= '<tr><td width="50%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$display .= '<td width="20%">' . $user . '</td>';
$display .= '<td width="20%">' . $forum . '</td>';
$display .= '<td width="10%">' . $replies . '</td></tr>';
}
}
$display .= '</table>';
return $display;
}
10
8
Quote
Status: offline
eyecravedvd
Forum User
Full Member
Registered: 06/09/03
Posts: 152
Thanks again, but that didn't return any results... before I noticed your post I did some more playing and ended with this, which just repeats the last post 4x (because there are 4 posts)
global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$sql = "SELECT p.post_id, p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username, f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id = f.forum_id
ORDER BY p.post_id DESC
LIMIT 10";
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="40%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="30%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
$results = mysql_query($sql);
if($row = mysql_fetch_array($results)) {
$topic = stripslashes($row["topic_title"]);
$post = $row["post_id"];
$user = $row["username"];
$forum = $row["forum_name"];
$replies = $row["topic_replies"];
do {
$display .= '<tr><td width="40%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$display .= '<td width="20%">' . $user . '</td>';
$display .= '<td width="30%">' . $forum . '</td>';
$display .= '<td width="10%">' . $replies . '</td></tr>';
}
while ($row = mysql_fetch_array($results));
} else {
$display .="Sorry, no records were found!";
}
$row++;
$display .= '</table>';
return $display;
}
Shane | www.EyeCraveDVD.com
Text Formatted Code
function getPosts() {global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$sql = "SELECT p.post_id, p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username, f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id = f.forum_id
ORDER BY p.post_id DESC
LIMIT 10";
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="40%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="30%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
$results = mysql_query($sql);
if($row = mysql_fetch_array($results)) {
$topic = stripslashes($row["topic_title"]);
$post = $row["post_id"];
$user = $row["username"];
$forum = $row["forum_name"];
$replies = $row["topic_replies"];
do {
$display .= '<tr><td width="40%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$display .= '<td width="20%">' . $user . '</td>';
$display .= '<td width="30%">' . $forum . '</td>';
$display .= '<td width="10%">' . $replies . '</td></tr>';
}
while ($row = mysql_fetch_array($results));
} else {
$display .="Sorry, no records were found!";
}
$row++;
$display .= '</table>';
return $display;
}
Shane | www.EyeCraveDVD.com
24
11
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
don't use $row++, that wont add anything to the iteration. get the row count and then use "$i=0;" and then at the end of "do", "while $i
in my last bit of code, if you don't define a funtion, then you could just echo the output rather than adding it to $display. that would work.
it's just that the variables inside the loop are being improperly concatenated, i think.
my last try
global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT" . $count;
//table headings
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
if($row = mysql_query($sql)) {
$rowcount = mysql_num_rows($row);
$i = 0;
//table content
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$loop = "";
if ($i > 0){
$loop .= $tablerow;
}
$tablerow = '<tr><td width="50%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$tablerow .= '<td width="20%">' . $user . '</td>';
$tablerow .= '<td width="20%">' . $forum . '</td>';
$tablerow .= '<td width="10%">' . $replies . '</td></tr>';
$loop = $loop . $tablerow;
$i++;
}
$display .= $loop;
}
$display .= '</table>';
return $display;
}
in my last bit of code, if you don't define a funtion, then you could just echo the output rather than adding it to $display. that would work.
it's just that the variables inside the loop are being improperly concatenated, i think.
my last try
Text Formatted Code
function getPosts() {global $_CONF;
$forum_url = "http://www.the-harbour.ca/forums";
$count = "10";
$sql = "SELECT x.post_subject, p.post_id, p.topic_id, p.forum_id, p.poster_id,
t.topic_title, t.topic_id, t.topic_replies, u.user_id, u.username,
f.forum_id, f.forum_name
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_forums f,
phpbb_posts_text x
WHERE p.topic_id = t.topic_id AND p.poster_id = u.user_id AND p.forum_id =
f.forum_id AND x.post_id = p.post_id
ORDER BY p.post_id DESC
LIMIT" . $count;
//table headings
$display = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr>';
$display .= '<th width="50%" style="font-weight: bold;">Topic</th><th width="20%" style="font-weight: bold;">Poster</th><th width="20%" style="font-weight: bold;">Forum</th><th width="10%" style="font-weight: bold;">Replies</th></tr>';
if($row = mysql_query($sql)) {
$rowcount = mysql_num_rows($row);
$i = 0;
//table content
while($m = mysql_fetch_array($row)) {
$topic = stripslashes($m["topic_title"]);
$post = $m["post_id"];
$user = $m["username"];
$forum = $m["forum_name"];
$replies = $m["topic_replies"];
$loop = "";
if ($i > 0){
$loop .= $tablerow;
}
$tablerow = '<tr><td width="50%" style="font-weight: bold;"><a title="' . $topic . '" href="' . $forum_url . '/viewtopic.php?p=' . $post . '">' . $topic . '</a></td>';
$tablerow .= '<td width="20%">' . $user . '</td>';
$tablerow .= '<td width="20%">' . $forum . '</td>';
$tablerow .= '<td width="10%">' . $replies . '</td></tr>';
$loop = $loop . $tablerow;
$i++;
}
$display .= $loop;
}
$display .= '</table>';
return $display;
}
9
9
Quote
Status: offline
eyecravedvd
Forum User
Full Member
Registered: 06/09/03
Posts: 152
Thanks for the try I still get nothing. I will see what I can find on the net.
I appreciate all your help.
Shane | www.EyeCraveDVD.com
I appreciate all your help.
Shane | www.EyeCraveDVD.com
9
8
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
whoops! lol . get rid of the $loop = "";
that just erases whatever you put in it in the previous loop.
ah well, kinda hard to test when i don't see results, so it'll probably not work anyway. sorry I couldn't help.
excuse me now while I hang up my cosey combat poncho.
that just erases whatever you put in it in the previous loop.
ah well, kinda hard to test when i don't see results, so it'll probably not work anyway. sorry I couldn't help.
excuse me now while I hang up my cosey combat poncho.
9
11
Quote
Status: offline
eyecravedvd
Forum User
Full Member
Registered: 06/09/03
Posts: 152
In my do code I just moved my variables into the do loop and it fixed it. Thanks for all your help. It is very much appreciated.
Shane | www.EyeCraveDVD.com
Shane | www.EyeCraveDVD.com
11
11
Quote
All times are EST. The time is now 09:54 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content