Jump to content

doddsey_65

Members
  • Posts

    902
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by doddsey_65

  1. i have some code which checks all of the posts in the database with the topic_id of $topic_id. what i want to do is like on many forums. On the topic list next to the name just show the pages like: 1-2-3-4 and when there are more than 4 or so 1-2....8-9 here is the code which gets the number of pages: $data = $db->query("SELECT * FROM ".DB_PREFIX."posts WHERE topic_id = '$topic_info->topic_id'"); $rows = mysql_num_rows($data); $page_rows = $posts_per_page; if ($rows > $page_rows) { $rowsArray = array($rows); } as you can see i have added it into an array but i dont know what to do from there. I guessed it would be something like a for statement but im not sure. Can anyone help?
  2. sorry i fixed it, i added a comma instead of the period. It works!! Thanks alot! I couldnt have done it without you all! I can now put this topic to rest.
  3. i get a parse error with that but i just changed the ; to a . But now i get the error: Warning: implode() [function.implode]: Argument must be an array in C:\wamp\www\myforum\modules\pages\forums.php on line 48 Sorry if this is frustrating you lol. And thanks for all the help thus far
  4. Thanks for the reply. I used your code and did get a few errors. Some were just typos though. There was one saying $userClass was undefined so i defined it as $userClass=''; before the switch. But the site isnt displaying the data properly. it just displays the three headers with the words array then the number 1 above them. Heres the code with the few changes i made to fix the errors: function createTable($parentData) { //Exit if this is the first record if($parentData['parent_id']===false) { return false; } $output = "<table class=\"forum_table\" onclick=\"expandCollapseTable(this)\">\n"; $output .= "<tr id=\"tr1\">\n"; $output .= "<th class=\"forum_left_corner\"></th>\n"; $output .= "<th class=\"forum_parent_name\">{$parentData['parent_name']}</th>\n"; $output .= "<th class=\"empty\"></th>\n"; $output .= "<th class=\"empty\"></th>\n"; $output .= "<th class=\"forum_last_post_header\">".LAST_POST."</th>\n"; $output .= "</tr>\n"; $output .= print_r("\n". $parentData['records']); return $output; } //Create and run query to get all the data $query = $db->query("SELECT f.forum_id, f.forum_name, f.forum_description, f.forum_topics, f.forum_posts, f.forum_last_poster, f.forum_last_post_time, f.forum_last_post, p.parent_id, p.parent_name, m.user_id, m.user_username, m.user_group, t.topic_id, t.topic_name, po.post_id, po.post_subject FROM ".DB_PREFIX."forums as f JOIN ".DB_PREFIX."parents as p ON f.parent_id = p.parent_id LEFT JOIN ".DB_PREFIX."members as m ON f.forum_last_poster = m.user_id LEFT JOIN ".DB_PREFIX."topics as t ON f.forum_id = t.forum_id LEFT JOIN ".DB_PREFIX."posts as po ON po.post_id = f.forum_last_post ORDER BY p.parent_id") or trigger_error("SQL", E_USER_ERROR); //Loop through records to process data $parentData = array('parent_id' => false); while ($forum_info = mysql_fetch_object($query)) { //Detect if this record is in a new parent id from the last if($forum_info->parent_id!=$parentData['parent_id']) { //Create table output for last parent data echo createTable($parentData); //Set new parent ID/name $parentData['parent_id'] = $forum_info->parent_id; $parentData['parent_name'] = $forum_info->parent_name; //Reset the data array $parentData['records'] = array(); } //Create url string $forum_url_name = str_replace(' ', '_', $forum_info->forum_name); //Create HTML output for current record $recordHTML = " <tr class=\"gradient\">\n"; $recordHTML .= " <td class=\"forum_icon\">\n"; $recordHTML .= " <div class=\"thread_icon\">{$forum_info->forum_id}</div>\n"; $recordHTML .= " </td>\n"; $recordHTML .= " <td class=\"forum_name\">\n"; $recordHTML .= " <p class=\"forum_name\">\n"; $recordHTML .= " <a href=\"index.php?forum=\{$forum_info->forum_id}&name={$forum_url_name}\">{$forum_info->forum_name}</a>\n"; $recordHTML .= " </p>\n"; $recordHTML .= " <p class=\"forum_description\">{$forum_info->forum_description}</p>\n"; $recordHTML .= " </td>\n"; $recordHTML .= " <td class=\"forum_topics\">{$forum_info->forum_topics}<span class=\"small_word\">".TOPICS."</span></td>\n"; $recordHTML .= " <td class=\"forum_posts\">{$forum_info->forum_posts}<span class=\"small_word\">".POSTS."</span></td>\n"; $recordHTML .= " <td class=\"forum_last_post\">\n"; if(!$forum_info->forum_last_poster || $forum_info->forum_last_poster==0) { $recordHTML .= "<p class=\"noposts\">".NO_POSTS."</p><p class=\"be_the_first\">".BE_FIRST."</p>\n"; } else { $forum_last_post_clean = str_replace(' ', '_', $forum_info->user_username); $last_post = date("F j, Y", strtotime($forum_info->forum_last_post_time)); if ($last_post == date('F j, Y')) { $last_post = 'Today at '.date("g:i a", strtotime($forum_info->forum_last_post_time)); } $recordHTML .= "<p class=\"last_post_name\">\n"; $recordHTML .= "<a href=\"index.php?topic={$forum_info->topic_id}&name={$forum_last_post_clean}\">{$forum_info->post_subject}</a>\n"; $recordHTML .= "</p>\n"; $userClass = ''; switch($forum_info->forum_last_poster) { case 1: $userClass .= 'admin'; break; case 2: $userClass .= 'mod'; break; case 3: case 0: default: $userClass .= 'user'; break; } $recordHTML .= "<p class=\"posted_by\">Posted By - <span class=\"{$userClass}\">{$forum_info->user_username}}</span></p>\n"; $recordHTML .= "<p class=\"last_post_date\">{$last_post}</p>\n"; } $recordHTML .= "</td>\n"; $recordHTML .= "</tr>\n"; //Add the record HTML to records array $parentData['records'][] = $recordHTML; } //Display records for last parent ID echo createTable($parentData); ?> Here is the sql dump also for the database if it helps. This code will be open source when i finish so im not too fussed about people knowing the layout. There are bound to be changes anyway. CREATE TABLE IF NOT EXISTS `forum_config` ( `config_id` int(11) NOT NULL AUTO_INCREMENT, `config_site_root` varchar(55) NOT NULL, `config_site_name` varchar(55) NOT NULL, `config_word_filter` int(1) NOT NULL DEFAULT '1', PRIMARY KEY (`config_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `forum_config` -- INSERT INTO `forum_config` (`config_id`, `config_site_root`, `config_site_name`, `config_word_filter`) VALUES (1, 'http://localhost/myforum', 'ASF', 0); -- -------------------------------------------------------- -- -- Table structure for table `forum_forums` -- CREATE TABLE IF NOT EXISTS `forum_forums` ( `forum_id` int(11) NOT NULL AUTO_INCREMENT, `parent_id` int(11) NOT NULL, `forum_name` varchar(100) NOT NULL, `forum_description` varchar(500) NOT NULL, `forum_topics` int(11) NOT NULL, `forum_posts` int(11) NOT NULL, `forum_last_post` int(11) NOT NULL, `forum_last_post_time` datetime NOT NULL, `forum_last_poster` int(11) NOT NULL, PRIMARY KEY (`forum_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; -- -- Dumping data for table `forum_forums` -- INSERT INTO `forum_forums` (`forum_id`, `parent_id`, `forum_name`, `forum_description`, `forum_topics`, `forum_posts`, `forum_last_post`, `forum_last_post_time`, `forum_last_poster`) VALUES (4, 3, 'Offtopic Chat', 'If you have something to say, something that maybe doesn''t quite fit anywhere else, then post it here. This is where you can talk about anything and everything.', 1, 1, 11, '2010-09-12 06:11:22', 27), (3, 2, 'Have an Idea?', 'Everyone building a project from the ground up needs ideas. And that''s where you come in. You may have an idea for a new feature or you may have a better design. Whatever it is, share it here.', 0, 0, 0, '0000-00-00 00:00:00', 0), (1, 1, 'Welcome', 'Are you new to the forum? If so then this is the place to start. Post an introduction and get aquainted with the staff and friendly members of our community.', 1, 1, 22, '2010-09-18 04:55:49', 27), (5, 1, 'New Features', 'All new features that have already been implemented wil be posted here. This is the place to come if you want to find out about them or talk about them.', 0, 0, 0, '0000-00-00 00:00:00', 0), (2, 1, 'Coming Soon', 'Coming soon to a forum near you. Interested to find out what is going on behind the scenes? Well you will find out everything you need to know here, including the latest features.', 0, 0, 0, '0000-00-00 00:00:00', 0); CREATE TABLE IF NOT EXISTS `forum_members` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_username` varchar(32) NOT NULL, `user_email` varchar(100) NOT NULL, `user_password` varchar(55) NOT NULL, `user_real_name` varchar(32) NOT NULL, `user_group` int(1) NOT NULL, `user_register_ip` varchar(32) NOT NULL, `user_regdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `user_birthday` varchar(5) NOT NULL DEFAULT '00-00', `user_online` int(1) NOT NULL, `user_group_color` varchar(6) NOT NULL, `user_avatar` varchar(150) NOT NULL DEFAULT 'avatars/none.png', `user_sex` varchar(1) NOT NULL, `user_location` varchar(32) NOT NULL, `user_confirmed` int(1) NOT NULL, `user_show_sex` int(1) NOT NULL DEFAULT '0', `user_show_location` int(1) NOT NULL DEFAULT '0', `user_show_status` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ; INSERT INTO `forum_members` (`user_id`, `user_username`, `user_email`, `user_password`, `user_real_name`, `user_group`, `user_register_ip`, `user_regdate`, `user_birthday`, `user_online`, `user_group_color`, `user_avatar`, `user_sex`, `user_location`, `user_confirmed`, `user_show_sex`, `user_show_location`, `user_show_status`) VALUES (27, 'doddsey65', '[email protected]', 'ff97e4e4e184e00299c90eac38d54799c97096d2', '', 1, '127.0.0.1', '2010-09-21 14:40:39', '11-11', 1, 'ff0000', 'avatars/asf.jpg', 'm', 'UK North East', 1, 1, 1, 1); CREATE TABLE IF NOT EXISTS `forum_parents` ( `parent_id` int(11) NOT NULL AUTO_INCREMENT, `parent_name` varchar(100) NOT NULL, PRIMARY KEY (`parent_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `forum_parents` -- INSERT INTO `forum_parents` (`parent_id`, `parent_name`) VALUES (1, 'Forum and Site News'), (2, 'Share Your Ideas'), (3, 'Offtopic Chat'); -- -------------------------------------------------------- -- -- Table structure for table `forum_posts` -- CREATE TABLE IF NOT EXISTS `forum_posts` ( `post_id` int(11) NOT NULL AUTO_INCREMENT, `topic_id` int(11) NOT NULL, `forum_id` int(11) NOT NULL, `post_poster` int(11) NOT NULL, `post_subject` varchar(100) NOT NULL, `post_content` longtext NOT NULL, `post_time` datetime NOT NULL, `post_edit_by` varchar(32) NOT NULL, `post_edit_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `post_approved` int(1) NOT NULL DEFAULT '0', `post_quoting` varchar(32) NOT NULL, PRIMARY KEY (`post_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=110 ; -- -- Dumping data for table `forum_posts` -- INSERT INTO `forum_posts` (`post_id`, `topic_id`, `forum_id`, `post_poster`, `post_subject`, `post_content`, `post_time`, `post_edit_by`, `post_edit_date`, `post_approved`, `post_quoting`) VALUES (22, 23, 1, 27, 'Welcome To ASF', 'Hi and Welcome to ASF Forums. \r\n\r\nFirst, let me thank you for visiting this site while it is still in production. If you come accross any errors please let us know via the contact page or on the forum thread [url=http://forum.nystic.com/viewtopic.php?f=27&t=11986]here[/url].\r\n\r\nAs we are still in development not all features may work. This may be due to them being currently worked on and we ask for your patience while we add such features. Please keep checking back on our progress.\r\n\r\nWe hope you like what you see. If you have any questions or comments then please register and post a thread.\r\n\r\nThanks', '2010-09-18 04:55:49', '', '0000-00-00 00:00:00', 0, ''), (11, 19, 4, 27, 'Thanks To BillyMcguffin', 'Thanks go to [b]Billy Mcguffin[/b] for his logo, which is now the main logo for ASF forums.', '2010-09-12 02:09:13', '', '0000-00-00 00:00:00', 0, ''); -- -------------------------------------------------------- -- -- Table structure for table `forum_sessions` -- CREATE TABLE IF NOT EXISTS `forum_sessions` ( `session_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `session` int(11) NOT NULL, `ip` varchar(11) NOT NULL, `browser` varchar(255) NOT NULL, `date` date NOT NULL, PRIMARY KEY (`session_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ; -- -- Dumping data for table `forum_sessions` -- -- -------------------------------------------------------- -- -- Table structure for table `forum_topics` -- CREATE TABLE IF NOT EXISTS `forum_topics` ( `topic_id` int(11) NOT NULL AUTO_INCREMENT, `forum_id` int(11) NOT NULL, `topic_name` varchar(100) NOT NULL, `topic_poster` int(11) NOT NULL, `topic_time_posted` datetime NOT NULL, `topic_views` int(11) NOT NULL, `topic_replies` int(11) NOT NULL, `topic_last_poster` int(11) NOT NULL, `topic_last_post_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `topic_locked` int(1) NOT NULL DEFAULT '0', `topic_sticky` int(1) NOT NULL DEFAULT '0', PRIMARY KEY (`topic_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ; -- -- Dumping data for table `forum_topics` -- INSERT INTO `forum_topics` (`topic_id`, `forum_id`, `topic_name`, `topic_poster`, `topic_time_posted`, `topic_views`, `topic_replies`, `topic_last_poster`, `topic_last_post_time`, `topic_locked`, `topic_sticky`) VALUES (19, 4, 'Thanks To BillyMcguffin', 27, '2010-09-18 04:44:25', 0, 0, 27, '2010-09-12 01:06:00', 0, 0), (23, 1, 'Welcome To ASF', 27, '2010-09-18 04:55:49', 129, 0, 27, '2010-09-18 03:55:00', 0, 0); -- -------------------------------------------------------- -- -- Table structure for table `forum_user_details` -- CREATE TABLE IF NOT EXISTS `forum_user_details` ( `user_id` int(11) NOT NULL, `user_fname` varchar(32) NOT NULL, `user_lname` varchar(32) NOT NULL, `user_avatar` varchar(255) NOT NULL, `user_sig` varchar(500) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `forum_user_details` -- INSERT INTO `forum_user_details` (`user_id`, `user_fname`, `user_lname`, `user_avatar`, `user_sig`) VALUES (27, '', '', 'avatars/asf.jpg', ' [left][img=http://img178.imageshack.us/img178/7157/mainlogo.jpg][/left] [right][size=32][b][url=http://thevault.cz.cc]ASF - A Simple Forum[/url][/b][/size][/right] '); By the looks of it the code is exactly what i need. Maybe just a problem with the print_r. Ive never used arrays before so i wouldnt know. Thanks
  5. thanks for the reply. I have tried print rather than return and it works fine.
  6. i wanted to print it on the screen. so the output would be <label for='username'>Username Am i going the wrong way about this?
  7. Hi, i have a class which i am writing(just a small test) which is supposed to create a label for a form but nothing is showing up. Here is the html part: $frobj=new asf_form(); $frobj->form_label('Username'); and here is the class code: function form_label($label='') { if($label == '') { return false; } else { return '<label for='.$label.'>'.$label; } } Have i done something wrong?
  8. thanks keith, i did implement your code but it is making a new table for each parent id. ie/ every record is in a new table rather than all records under the same parent_id in the same table. I will upload the file to the server so you can have a look here: http://thevault.cz.cc
  9. okay let me put a stop to this, since i always come here first for help. Im sorry if you think i am being argumentative, or what i said was potrayed as such. Thats not what i meant to happen. Maybe just a little frustration on my part for not being able to understand. I only said i needed the loop within a loop because i couldnt see any other way. And yes your wuery did return all of the results and that has been implemented but that isnt the issue now. The new issue was about the table headers. I accept the blame though, as i never seem to be able to clearly explain a problem. It seems so simple in my head but i can never get it into words properly. Sorry
  10. well i used to think this was a firendly community until now. No i am not lazy, i simply didnt understand. I never asked anyone to do the work for me i asked for help. I still dont understand the solution to my problem as i am fairly new to php but it doesnt matter now. I will just close this topic and get help elsewhere.
  11. what about this then: $parent_info_query = $db->query("SELECT p.parent_id, p.parent_name FROM ".DB_PREFIX."parents as p ORDER BY p.parent_id") or trigger_error("SQL", E_USER_ERROR); while ($parent_info = mysql_fetch_object($parent_info_query)) { // Add parent_id into variable for later query $parent_id = $parent_info->parent_id; echo '<table class="forum_table" onclick="expandCollapseTable(this)"> <tr id="tr1"> <th class="forum_left_corner"></th> <th class="forum_parent_name">'.$parent_info->parent_name.'</th> <th class="empty"></th> <th class="empty"></th> <th class="forum_last_post_header">'.LAST_POST.'</th> </tr>'; $forum_info_query = $db->query("SELECT f.forum_id, f.forum_name, f.forum_description, f.forum_topics, f.forum_posts, f.forum_last_poster, f.forum_last_post_time, f.forum_last_post, m.user_id, m.user_username, m.user_group, t.topic_id, t.topic_name, po.post_id, po.post_subject FROM ".DB_PREFIX."forums as f LEFT JOIN ".DB_PREFIX."members as m ON f.forum_last_poster = m.user_id LEFT JOIN ".DB_PREFIX."topics as t ON t.forum_id = f.forum_id LEFT JOIN ".DB_PREFIX."posts as po ON po.post_id = f.forum_last_post WHERE f.parent_id = '$parent_id' ORDER BY f.forum_id") or trigger_error("SQL", E_USER_ERROR); while ($forum_info = mysql_fetch_object($forum_info_query)) { // Get Forum information from DB to show all forums // including who the last post was posted by echo '<tr class="gradient">'; $forum_url_name = $forum_info->forum_name; $forum_url_name = str_replace(' ', '_', $forum_url_name); echo ' <td class="forum_icon"> <div class="thread_icon"></div> </td> <td class="forum_name"> <p class="forum_name"><a href="index.php?forum= '. $forum_info->forum_id . ' &name= '.$forum_url_name.' "> ' . $forum_info->forum_name .' </a></p> <p class="forum_description"> ' . $forum_info->forum_description .' </p></td> <td class="forum_topics"> '. $forum_info->forum_topics .' <span class="small_word"> '.TOPICS.'</span></td> <td class="forum_posts"> '. $forum_info->forum_posts .' <span class="small_word"> '.POSTS.'</span></td> <td class="forum_last_post">'; if (!$forum_info->forum_last_poster) { echo '<p class="noposts">'.NO_POSTS.'</p> <p class="be_the_first">'.BE_FIRST.'</p>'; } elseif ($forum_info->forum_last_post == 0) { echo '<p class="noposts">'.NO_POSTS.'</p> <p class="be_the_first">'.BE_FIRST.'</p>'; } else { $forum_last_post_clean = str_replace(' ', '_', $forum_info->user_username); echo '<p class="last_post_name"><a href="index.php?topic='.$forum_info->topic_id.' &name='.$forum_last_post_clean.'">'.$forum_info->post_subject.'</a></p>'; echo '<p class="posted_by">Posted By - '; $today = date('F j, Y'); $last_post = date("F j, Y", strtotime($forum_info->forum_last_post_time)); if ($last_post == $today) { $last_post = 'Today at '.date("g:i a", strtotime($forum_info->forum_last_post_time)); } else { $last_post = date("F j, Y - g:i a", strtotime($forum_info->forum_last_post_time)); } if ($forum_info->user_group == 1) { echo '<span class="admin">'; } elseif ($forum_info->user_group == 2) { echo '<span class="mod">'; } elseif ($forum_info->user_group == 3) { echo '<span class="user">'; } elseif ($forum_info->user_group == 0) { echo '<span class="user">'; } echo $forum_info->user_username .'</span></p> <p class="last_post_date">' .$last_post; } echo '</p></td></tr>'; } } As you can see the first query ($parent_info_query) gets the parent name and parent id so i can use the parent id in the next query ($forum_info_query) so i can use WHERE parent_id = $parent_id. This is so it groups the results into the respective categories. Is there a way to do this without a loop in a loop? and why is this bad practice? Thanks
  12. i never asked you to rewrite the code, i asked for help on my code and why it is behaving as such
  13. i just tried to echo the query and it outputted this: Resource id #11
  14. it is grouping them by parent_id but each record is in its own table with its own <th>s. What i need is so that records with parent_id 1 are in a table with <th>s and records with parent_id 2 in a different table with <th>s and so on. Heres my code so far: $forum_info_query = $db->query("SELECT f.forum_id, f.forum_name, f.forum_description, f.forum_topics, f.forum_posts, f.forum_last_poster, f.forum_last_post_time, f.forum_last_post, p.parent_id, p.parent_name, m.user_id, m.user_username, m.user_group, t.topic_id, t.topic_name, po.post_id, po.post_subject FROM ".DB_PREFIX."forums as f JOIN ".DB_PREFIX."parents as p ON f.parent_id = p.parent_id LEFT JOIN ".DB_PREFIX."members as m ON f.forum_last_poster = m.user_id LEFT JOIN ".DB_PREFIX."topics as t ON f.forum_id = t.forum_id LEFT JOIN ".DB_PREFIX."posts as po ON po.post_id = f.forum_last_post ORDER BY p.parent_id") or trigger_error("SQL", E_USER_ERROR); while ($forum_info = mysql_fetch_object($forum_info_query)) { // Add parent_id into variable for later query $parent_id = $forum_info->parent_id; echo '<table class="forum_table" onclick="expandCollapseTable(this)"> <tr id="tr1"> <th class="forum_left_corner"></th> <th class="forum_parent_name">'.$forum_info->parent_name.'</th> <th class="empty"></th> <th class="empty"></th> <th class="forum_last_post_header">'.LAST_POST.'</th> </tr>'; // Get Forum information from DB to show all forums // including who the last post was posted by echo '<tr class="gradient">'; $forum_url_name = $forum_info->forum_name; $forum_url_name = str_replace(' ', '_', $forum_url_name); echo ' <td class="forum_icon"> <div class="thread_icon">'.$forum_info->forum_id.'</div> </td> <td class="forum_name"> <p class="forum_name"><a href="index.php?forum= '. $forum_info->forum_id . ' &name= '.$forum_url_name.' "> ' . $forum_info->forum_name .' </a></p> <p class="forum_description"> ' . $forum_info->forum_description .' </p></td> <td class="forum_topics"> '. $forum_info->forum_topics .' <span class="small_word"> '.TOPICS.'</span></td> <td class="forum_posts"> '. $forum_info->forum_posts .' <span class="small_word"> '.POSTS.'</span></td> <td class="forum_last_post">'; if (!$forum_info->forum_last_poster) { echo '<p class="noposts">'.NO_POSTS.'</p> <p class="be_the_first">'.BE_FIRST.'</p>'; } elseif ($forum_info->forum_last_post == 0) { echo '<p class="noposts">'.NO_POSTS.'</p> <p class="be_the_first">'.BE_FIRST.'</p>'; } else { $forum_last_post_clean = str_replace(' ', '_', $forum_info->user_username); echo '<p class="last_post_name"><a href="index.php?topic='.$forum_info->topic_id.' &name='.$forum_last_post_clean.'">'.$forum_info->post_subject.'</a></p>'; echo '<p class="posted_by">Posted By - '; $today = date('F j, Y'); $last_post = date("F j, Y", strtotime($forum_info->forum_last_post_time)); if ($last_post == $today) { $last_post = 'Today at '.date("g:i a", strtotime($forum_info->forum_last_post_time)); } else { $last_post = date("F j, Y - g:i a", strtotime($forum_info->forum_last_post_time)); } if ($forum_info->user_group == 1) { echo '<span class="admin">'; } elseif ($forum_info->user_group == 2) { echo '<span class="mod">'; } elseif ($forum_info->user_group == 3) { echo '<span class="user">'; } elseif ($forum_info->user_group == 0) { echo '<span class="user">'; } echo $forum_info->user_username .'</span></p> <p class="last_post_date">' .$last_post; } echo '</p></td></tr>'; } also one of the records(just one) is displayed twice. I can do an export of the forum table in the database if that helps.
  15. as far as i can see(been testing) i need the 2 queries. The first gets all parents so it can group the next query results in each table.
  16. thanks, it worked. I used your example and changed a few things. I also added the loop but they are no longer being grouped in their parents. They should be grouped by their parent id into different tables, but they arent anymore. Here is the link to the live version which shows what i mean about the grouping: http://thevault.cz.cc But they are all now in their own single tables.
  17. UPDATE: I have realised that the wuery is not pulling the forums with no topics or replies. I think this is due to this bit of code in the query: JOIN ".DB_PREFIX."members ON ".DB_PREFIX."forums.forum_last_poster = ".DB_PREFIX."members.user_id but i need that in to pull the username of the last poster. Any other way of doing this?
  18. I have this code which should get all the results from forum_forums and list them in their respective parents using forum_forums.parent_id. It does work sort of but it repeats one of them and doesnt include all of them. Can anyone see where i am going wrong? $parent_info_query = $db->query("SELECT parent_id, parent_name FROM ".DB_PREFIX."parents") or die(mysql_error()); while ($parent_info = mysql_fetch_object($parent_info_query)) { // Add parent_id into variable for later query $parent_id = $parent_info->parent_id; echo '<table class="forum_table" onclick="expandCollapseTable(this)"> <tr id="tr1"> <th class="forum_left_corner"></th> <th class="forum_parent_name">'.$parent_info->parent_name.'</th> <th class="empty"></th> <th class="empty"></th> <th class="forum_last_post_header">'.LAST_POST.'</th> </tr>'; // Get Forum information from DB to show all forums // including who the last post was posted by $forum_info_query = $db->query("SELECT ".DB_PREFIX."forums.forum_id, ".DB_PREFIX."forums.forum_name, ".DB_PREFIX."forums.forum_description, ".DB_PREFIX."forums.forum_topics, ".DB_PREFIX."forums.forum_posts, ".DB_PREFIX."forums.forum_last_poster, ".DB_PREFIX."forums.forum_last_post_time, ".DB_PREFIX."forums.forum_last_post, ".DB_PREFIX."members.user_id, ".DB_PREFIX."members.user_username, ".DB_PREFIX."members.user_group, ".DB_PREFIX."topics.topic_id, ".DB_PREFIX."topics.topic_name FROM ".DB_PREFIX."forums JOIN ".DB_PREFIX."members ON ".DB_PREFIX."forums.forum_last_poster = ".DB_PREFIX."members.user_id JOIN ".DB_PREFIX."topics ON ".DB_PREFIX."forums.forum_id = ".DB_PREFIX."topics.forum_id WHERE ".DB_PREFIX."forums.parent_id = $parent_id") or trigger_error("SQL", E_USER_ERROR); while ($forum_info = mysql_fetch_object($forum_info_query)) {
  19. thanks, the expand collapse works perfectly when i added it to my code. i realise there are several coding issues and cleanups to be done. I have started doing this on another page, including table joins and classes. Just havent got far with it. Thanks alot. maybe if you have time later you could have a look at the page i have cleaned up and see if everything within it is clean and good standard. Only if you have time though.
  20. hi, im looking for a way to collapse table rows that are created using a while loop. I have looked around on google and nothing seems to work for me. Here is the code which generates my tables. I basically want all of the <tr>s in the table to collapse leaving only the <th>s. echo '<table class="forum_table"><tr><th class="forum_left_corner"></th><th class="forum_parent_name">'.$parent_name.'</th><th class="empty"></th><th class="empty"></th><th class="forum_last_post_header">'.LAST_POST.'</th></tr>';$sql2 = mysql_query("SELECT forum_id, forum_name, forum_description, forum_topics, forum_posts, forum_last_poster, forum_last_post_time, forum_last_post FROM ".DB_PREFIX."forums WHERE parent_id = $parent_id ") or die (mysql_error());while ($row2 = mysql_fetch_object($sql2)) {echo '<tr class="gradient">'; //Collapse all of these so that only the above <th>s are visible$forum_url_name = $row2->forum_name;$forum_url_name = str_replace(' ', '_', $forum_url_name);echo '<td class="forum_icon"> <div class="thread_icon"> </div> </td> <td class="forum_name"> <p class="forum_name"><a href="index.php?forum='. $row2->forum_id . '&name='.$forum_url_name.'">' . $row2->forum_name .'</a></p> <p class="forum_description">' . $row2->forum_description .'</p></td> <td class="forum_topics">'. $row2->forum_topics .'<span class="small_word"> '.TOPICS.'</span></td> <td class="forum_posts">'. $row2->forum_posts .'<span class="small_word"> '.POSTS.'</span></td> <td class="forum_last_post">'; $sql6 = mysql_query("SELECT * FROM ".DB_PREFIX."members ") or die(mysql_error()); $row3 = mysql_fetch_object($sql6); $membergroup = $row3->user_group; if (!$row2->forum_last_poster) { echo '<p class="noposts">'.NO_POSTS.'</p> <p class="be_the_first">'.BE_FIRST.'</p>'; } else { $forum_last_post = $row2->forum_last_post; $forum_last_post_clean = str_replace(' ', '_', $row2->forum_last_post); $data = mysql_query("SELECT topic_id FROM ".DB_PREFIX."topics WHERE topic_name = '$forum_last_post'"); $topic = mysql_fetch_object($data); echo '<p class="last_post_name"><a href="index.php?topic='.$topic->topic_id.' &name='.$forum_last_post_clean.'">'.$row2->forum_last_post.'</a></p>'; echo '<p class="posted_by">Posted By - '; $today = date('F j, Y'); $last_post = date("F j, Y", strtotime($row2->forum_last_post_time)); if ($last_post == $today) { $last_post = 'Today at '.date("g:i a", strtotime($row2->forum_last_post_time)); } else { $last_post = date("F j, Y", strtotime($row2->forum_last_post_time)); } if ($membergroup == 1) { echo '<span class="admin">'; } elseif ($membergroup == 2) { echo '<span class="mod">'; } elseif ($membergroup == 3) { echo '<span class="user">'; } elseif ($membergroup == 0) { echo '<span class="user">'; }echo $row2->forum_last_poster .'</span></p> <p class="last_post_date">' .$last_post; }echo '</p></td></tr>';}} I hope someone can help with this. Thanks
  21. sorry but im still having trouble. normally i would give up but i need this feature in. so lets make it clear(hopefully lol) posts.php which shows all the posts for that forum reads like this: (simplified for example) <script type="text/javascript"> function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function AJAX(action) { var xmlHttp = createXMLHttpRequest(); var input=document.getElementById("input").value; params = "action=" + action + "&input=" + input; xmlHttp.open("POST","test.php", true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { document.getElementById("dynamic_update").innerHTML = xmlHttp.responseText; refresh_stats(); } } xmlHttp.send(params); } </script> <table> <th>Poster</th> <th>Content</th> <tr> <td>CONTENTS TO SHOW WHO POSTED IT</td> <td>CONTENTS OF THE POST</td> </tr></table> then in test.php i want <textarea id="input"></textarea> <input type="button" value="Submit" onClick="javascript:AJAX('update');"> and some other code so that when the user hits submit a new table row is added with the 2 new <td>s so that when they do hit submit the textarea contents go into the <td> which holds the post content and their user information( i can handle this part) goes into the first <td> the one which tells you who posted it.
  22. it works but the content is posted inside a td that already has content. I need it to make a new one. basically; im using a while loop to pull all records from the database that have an id equal to the get value. the records are put into a table with the post information going in the left td and the content going in the right td. When the user hits quick reply i want their reply to be put into a new tr underneath the others and have the contents of the quick reply in the right td in the new tr.
  23. Thanks, i got it working and it is also sending the input to the database. However i dont want it to be displayed in a div above the input. I want the data to be displayed in a td. Here is the layout of the table that shows the poster and the post contents. when i send it to the database everything is getting sent and the tables are populated with the correct data. so how would i make it so that it appears in the td <td class="post_content"> I tried to give this td the id dynamic_update but that didnt work. echo '<table class="post_table"> <tr> <th class="post_header_name">Posted By</th> <th class="post_content_header">Content</th> </tr>'; $sql1 = mysql_query("SELECT * FROM ".DB_PREFIX."posts WHERE topic_id = '$topic_id' ORDER BY post_time ASC $max") or die(mysql_error()); while ($posts = mysql_fetch_object($sql1)) { echo '<tr class="gradient">'; echo ' <td class="post_poster">'; echo '<p class="post_poster">'; echo '</p></p></td> <td class="post_content">'; echo '</td></tr>'; } }
  24. im trying to improve my code by using table joins but when i use the following code it just returns everything in the database rather than the results that equal $forum_id which is the get value 2. There should only be 2 results. $query = $db->query("SELECT ".DB_PREFIX."topics.topic_id, ".DB_PREFIX."topics.topic_name, ".DB_PREFIX."topics.topic_poster, ".DB_PREFIX."topics.topic_time_posted, ".DB_PREFIX."topics.topic_views, ".DB_PREFIX."topics.topic_replies, ".DB_PREFIX."topics.topic_last_poster, ".DB_PREFIX."topics.topic_last_post_time, ".DB_PREFIX."topics.topic_locked, ".DB_PREFIX."topics.topic_sticky, ".DB_PREFIX."parents.parent_id, ".DB_PREFIX."parents.parent_name, ".DB_PREFIX."forums.forum_name, ".DB_PREFIX."members.user_username, ".DB_PREFIX."members.user_group FROM ".DB_PREFIX."topics JOIN ".DB_PREFIX."members JOIN ".DB_PREFIX."parents JOIN ".DB_PREFIX."forums ON ".DB_PREFIX."topics.topic_poster = ".DB_PREFIX."members.user_username WHERE ".DB_PREFIX."forums.forum_id = ".$forum_id." ORDER BY ".DB_PREFIX."topics.topic_time_posted $max") or trigger_error("SQL", E_USER_ERROR);
  25. i would love to say that makes perfect sense and i get it but i dont sorry. I learnt php by myself and im not a good learner lol. lets see if i can make my request simpler. I have this in test.php: <SCRIPT> function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; }</SCRIPT> <SCRIPT> function AJAX(var1) { var xmlHttp = createXMLHttpRequest(); //var1 is passed with the function call, var2 is form data that can be retrieved var var2 = document.getElementById("var2data").value; //this sets up the parameters to be sent using the POST method later params = "var1=" + var1 + "&var2=" + var2; //this opens the target php file and tells it what method data will be sent in xmlHttp.open("POST","test.php", true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4 && xmlHttp5.status == 200) { //this tells it where to put the output of the target php file document.getElementById("dynamic_update").innerHTML = xmlHttp.responseText; } } //This sends the var1 and var2 variables we defined earlier via the POST method xmlHttp.send(params); } </SCRIPT> <div id="dynamic_update"> </div> <form name="test" action=""> <textarea name=""></textarea> <input type="submit" value="Submit" name="submit_btn" /> </form> when the user hits submit the div is instantly populated with the contents of textarea. how would i do that
×
×
  • Create New...

Important Information

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.