| View previous topic :: View next topic |
| Author |
Message |
santosh_iit32
 newbie
Member No.: 90 Joined: 19 Nov 2006 Posts: 21 Location: India
|
Posted: Mon Jan 08, 2007 12:16 pm Post subject: help with latest post again |
|
|
i get an error saying:
| Quote: |
| Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/username/public_html/hello.php on line 25 |
i think this is the line 25:
| Quote: |
| while($r=mysql_fetch_array($result)){ |
| Quote: |
$db_host = '127.0.0.1'; # Change to your host
$db_user = 'name'; # Change to your user name
$db_password = 'pass'; # Change to your password
$db_name = 'forum'; # Change to your db name
mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query("SELECT DISTINCT t.topic_id, t.topic_title, t.topic_replies, u.user_id, u.username, s.post_text
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_posts_text s
WHERE p.topic_id = t.topic_id AND t.topic_poster = u.user_id AND t.topic_first_post_id = s.post_id AND u.user_id != -1
ORDER BY p.post_time DESC LIMIT 7");
function text($text, $limit){
$text = str_replace("\n", " ", $text);
$text = preg_replace("#\[(.*?)\].*?\[/(\\1)\]#si", "[bbcode]", $text);
if(strlen($text)>$limit){
$text = substr($text, 0, $limit);
$text = substr($text, 0, -(strlen(strrchr($text, ' '))))."...";
}
return $text;
}
while($r=mysql_fetch_array($result)){
$text = text($r['post_text'], 50);
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"2\"> <a href=\"/forum/viewtopic.php?t={$r['topic_id']}\" target=\"_self\">{$r['topic_title']}</a></td></tr><tr><td align=\"left\">by: <a href=\"/forum/profile.php?mode=viewprofile&u={$r['user_id']}\" target=\"_self\">{$r['username']}</a></td><td align=\"right\"><p align=\"right\">Posted Reply {$r['topic_replies']}</td></tr><tr><td colspan=\"2\" height=\"6\"></td></tr><tr><td colspan=\"2\" height=\"1\" background=\"../graphics/line.gif\"></td></tr><tr><td colspan=\"2\" height=\"4\"></td></tr></table>";
}
?> |
could you please help me as to why I'm getting this error? thank you. |
|
| Back to top |
|
 |
rc69
 Site Admin

Member No.: 1 Joined: 05 Aug 2004 Posts: 152
|
Posted: Mon Jan 08, 2007 7:37 pm Post subject: |
|
|
Change the query to this:
| Code: |
$result = mysql_query("SELECT DISTINCT t.topic_id, t.topic_title, t.topic_replies, u.user_id, u.username, s.post_text
FROM phpbb_posts p, phpbb_topics t, phpbb_users u, phpbb_posts_text s
WHERE p.topic_id = t.topic_id AND t.topic_poster = u.user_id AND t.topic_first_post_id = s.post_id AND u.user_id != -1
ORDER BY p.post_time DESC LIMIT 7") or die(mysql_error()); |
_________________ Current user reading this: Anonymous
Mind the gap. |
|
| Back to top |
|
 |
santosh_iit32
 newbie
Member No.: 90 Joined: 19 Nov 2006 Posts: 21 Location: India
|
Posted: Thu Jan 11, 2007 1:15 am Post subject: |
|
|
| yeah i got it figure out now. thank you so much, admin. it means a lot to me. thank you once again |
|
| Back to top |
|
 |
santosh_iit32
 newbie
Member No.: 90 Joined: 19 Nov 2006 Posts: 21 Location: India
|
Posted: Mon Jan 15, 2007 7:15 am Post subject: |
|
|
sorry to bother again but is there a way to get "last poster name" and of course "date of posting"?
Thank you. |
|
| Back to top |
|
 |
rc69
 Site Admin

Member No.: 1 Joined: 05 Aug 2004 Posts: 152
|
Posted: Tue Jan 16, 2007 9:59 pm Post subject: |
|
|
Add topic_last_post_id to what you're selecting in the above query, then select the rest of the info you want later. _________________ Current user reading this: Anonymous
Mind the gap. |
|
| Back to top |
|
 |
santosh_iit32
 newbie
Member No.: 90 Joined: 19 Nov 2006 Posts: 21 Location: India
|
Posted: Wed Jan 17, 2007 3:01 am Post subject: |
|
|
| hey thanx for the tip, i'll try it out now. |
|
| Back to top |
|
 |
santosh_iit32
 newbie
Member No.: 90 Joined: 19 Nov 2006 Posts: 21 Location: India
|
Posted: Wed Jan 17, 2007 3:49 am Post subject: |
|
|
| hey i'm lost again trying to modify the codes, could your please help out. i would like the date of posting as well. thank you os much. |
|
| Back to top |
|
 |
rc69
 Site Admin

Member No.: 1 Joined: 05 Aug 2004 Posts: 152
|
Posted: Wed Jan 17, 2007 7:03 pm Post subject: |
|
|
Use the selected last_post_id to select the date out of the last post. I'd help more, but with limited time i can only tell you what to do. The point of these tutorials is to teach, not for me to help you modify it into something else.
Sorry. _________________ Current user reading this: Anonymous
Mind the gap. |
|
| Back to top |
|
 |
santosh_iit32
 newbie
Member No.: 90 Joined: 19 Nov 2006 Posts: 21 Location: India
|
Posted: Thu Jan 18, 2007 4:39 am Post subject: |
|
|
| thank you. let me try again. yes i do understand your limited time and i'm always grateful for the constant support from you. |
|
| Back to top |
|
 |
|