Jump to content

doddsey_65

Members
  • Posts

    902
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by doddsey_65

  1. anyone have any ideas? if i havent explained clearly enough then please ell me and i will try to elborate.
  2. im a step further forward. i can now show if a forum has sub forums but i am struggling to show the sub forum name. this is how i tell if a forum has any subforums: $fids = $pids = array(); foreach($row as $key => $value) { for($i=0; $i<count($row); $i++) { $fids[] = $row[$i]['f_fid']; $pids[] = $row[$i]['f_pid']; } if(in_array($forum_id, $pids)) { echo 'has child<br />'; } but i cant show the name. any ideas?
  3. im using the modified preorder tree traversal heirarchal system for my forum. (http://articles.sitepoint.com/article/hierarchical-data-database/2) basically where you store the left and right id to form relationships between forums like phpbb does. but im struggling to show subforums underneath their parents. eg: forum id left id right id parent id 1 1 8 0 this is a category 2 2 7 1 this is a forum belonging to the category 3 3 6 1 this is a forum belonging to the category 4 4 5 2 this is a subforum belonging to forum 2 i can display all of the forums within their categories fine but cant think how to add the subforums underneath the forums that have them. has anyone got any advice?
  4. thanks for the reply. im using PDO but found the function PDO::lastInsertId() to work
  5. when i insert a new topic into the database its id is generated by the auto incrememnt field tid. but what i do next is insert the post for that new topic in the post table which has p_pid(post id) and p_tid(the topic id it is for). so how do i generate that p_tid when the topic has just been inserted. i used to do it by inserting the topic then running a query to pull the newest topic if from the database which would mean the post belonged to that topic. but what happens when people are posting several topics at the same time?
  6. i have a form for which the data is sent to a process page via jquery like so: jQuery.post('<?php echo $this->site_root; ?>/modules/new_post_process.php',{ message:jQuery("#message_contents").val() } ,function(data) { etc... new_post_process checks the contents of message like so: if (empty($message) && empty($error)) { $is_error = true; $error = 'Please Enter A Message'; } the problem is that it always throws this message even when the textarea isnt empty. however after the error has appeared if i submit again it goes through fine. I suppressed the error and tried and the database gets populated with an empty value which means it is indeed empty. so why does it work on the second time around? I am using CKEditor for the textarea. everything else gets submitted normally but this textarea. heres the full code: the textarea: <textarea cols="80" rows="10" id="message_contents"></textarea> jQuery("#new_post_form").submit(function() { jQuery.post('<?php echo $this->site_root; ?>/modules/new_post_process.php',{ user_name:jQuery("#user_name").val(), redirect_url:jQuery("#redirect_url").val(), subject:jQuery("#subject_field").val(), forum_id:jQuery("#fid").val(), topic_id:jQuery("#tid").val(), method:jQuery("#method").val(), message:jQuery("#message_contents").val() } ,function(data) { if (data == 1) { jQuery("#process_info").removeClass().addClass("subject_okay").html("<img src=\"<?php echo $this->template_path; ?>icons/small_tick.png\" alt=\"icon\" />Redirecting...").fadeIn("slow"); var URL = jQuery("#redirect_url").val(); document.location = URL; } else { jQuery("#reply_btn").css("visibility", "visible"); jQuery("#draft_btn").css("visibility", "visible"); jQuery("#process_info").removeClass().addClass("subject_error").html('<img src="<?php echo $this->template_path; ?>icons/small_error.png" alt="icon" /> ' + data).fadeIn("slow"); } }); and the process page: if (isset($_POST['subject'])) { $message = $_POST['message']; if (empty($message) && empty($error)) { $is_error = true; $error = 'Please Enter A Message'; } if (empty($error) && $is_error == false) { $query = $link->prepare("INSERT INTO ".TBL_PREFIX."posts (p_fid, p_tid, p_poster, p_name, p_content, p_time_posted) VALUES ('$forum_id', '$topic_id', '$user_name', '$subject', '$message', '".$config['time_now']."') ") or die(print_link_error()); echo "1"; } else { echo $error.'-'.$message; }
  7. theres nothing wrong with the if statement its your echo: echo '<tr><td>$result</td></tr>'; anything inside single quotes doesnt get parsed by php therefore it will just echo $result. try: echo '<tr><td>'.$result.'</td></tr>';
  8. an easier method would be: $req_date = '03/02/2011'; $req_date = strtotime($req_date); $req_date >= strtotime('-5 DAYS') ? $result='Yes' : $result='No'; echo $result;
  9. i have a recent topics box on my homepage which shows the five most recent topics. this is the query to display them: $query = $link->query("SELECT t.t_name, t.t_poster, t.t_time_posted, t.t_views, t.t_replies, t.t_last_poster, t.t_last_post_time, u.u_avatar, f.f_name FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."users u ON (u.u_username = t.t_poster) JOIN ".TBL_PREFIX."forums as f ON (t.t_fid = f.f_fid) ORDER BY t_time_posted DESC LIMIT 5")or die(print_link_error()); $result = $query->fetchAll(); the problem is the url needs to be: ./category/the_category/forum/the_forum/topic/the_topic but with this code i can only pull the topic name and the forum name due to the database. i dont have a seperate table for categories. instead i have forums with a pid of 0 to denote a category and all forums within the category have a pid which is equal to the fid of the forum category: name fid pid category 1 0 forum 2 1 another 3 1 and so on. so how would i be able to get the category name aswell without running another query within my foreach loop? i tried joining the forums table again as c but that wouldnt help because the result would be looking for the name and it would appear twice within the query. Thanks
  10. removed everything down to the basic and i am getting undefined variable value here: public function __get($name) { if (isset($this->_data[$name])) { return $value; // error thrown here } return NULL; } EDIT: replace it with: public function __get($name) { if (isset($this->_data[$name])) { return $this->_data[$name]; } return NULL; } and it works fine
  11. found the reason. i am including a config.php file which holds: $config['asf_root'] = http://localhost/asf/'; and in the template.php file i have: public function set_template($template='default') { global $config; $this->template_root = $config['asf_root'].'templates/'; $this->template = $this->template_root.$template.'/'; } when i echo $config['asf_root'] it appears fine, but obv isnt working so i used the relative path and it worked in the test script. but in my main script the error has gone but it displays nothing.
  12. ive worked out when it is throwing the error. on my test script(by your example) everything worked fine. and this is the dir tree: ROOT FOLDER index.php = calls the page_header function from class_view while calls the render function init.php = starts the view class class_view.php = the view class tpl_index.php = the html for index.php but when i split up the files into different dirs: ROOT FOLDER index.php INCLUDES FOLDER class_view.php init.php TEMPLATES FOLDER DEFAULT FOLDER tpl_index.php i get the error: Fatal error: Using $this when not in object context in C:\wamp\www\test\templates\default\tpl_index.php on line 68 no idea why though.
  13. ive checked and done tests and header.php isnt being included other than the render function. the test was i got rid of: $template->page_header($lang->index); the function page_header calls the render function: public function render($template) { ob_start(); include($template); echo ob_get_clean(); } public function page_header($page_title) { global $date_time, $settings, $lang, $config, $user; $css_link = $this->template.'main.css'; $board_logo = '<img src="'.$this->template.'images/'.$settings['board_logo'].'" alt="'.$settings['board_name'].'" />'; $offset = $date_time->getOffset(); $curr_time = $date_time->getTimestamp(); $time = $curr_time - $offset; $this->board_name = 'boobs'; echo 'template = '.$this->template.'html/header.php'; $this->render($this->template.'html/header.php'); } i dont know why this is happening either as i have gotten your example to work on a test folder.
  14. Fatal error: Using $this when not in object context in C:\wamp\www\ASF\templates\default\html\header.php on line 76 and line 76 in header.php is: <?php echo $this->board_name; ?>
  15. ill clean it up a bit: header.php(the tpl file) [color=rgb(0, 0, 0)] <p id="name"> <?php echo $this->board_name; ?> </p>[/color] template.php class template { var $root = ''; var $template; var $template_root; private $_data = array(); public function __set($name, $value) { $this->_data[$name] = $value; } public function __get($name) { if (isset($this->_data[$name])) { return $value; } return NULL; } public function render($template) { ob_start(); include($template); echo ob_get_clean(); } function page_header($page_title) { global $settings; // settings.php $this->board_name = $settings['board_name']; $this->render($this->template.'html/header.php'); } } index.php $template->page_header('Board Index'); any clearer?
  16. $_POST['submit'] refers to the name of a submit button. your submit button doesnt have a name. change: [color=rgb(0, 0, 0)]<input type="submit" value="OK" />[/color] to: [color=rgb(0, 0, 0)]<input type="submit" name="submit" value="OK" />[/color]
  17. any ideas? i cant move on til i fix this.
  18. hi sorry for the late reply, been at work. here is the code i am using: header.php <p id="name"> <?php echo $this->board_name; ?> </p> template.php class template { var $root = ''; var $template; var $template_root; private $_data = array(); public function __set($name, $value) { $this->_data[$name] = $value; } public function __get($name) { if (isset($this->_data[$name])) { return $value; } return NULL; } public function set_template($template='default') { global $config; $this->template_root = $config['asf_root'].'templates/'; $this->template = $this->template_root.$template.'/'; } public function replace($array, $file) { $file = './html/'.$file.'.html'; $file = file_get_contents($this->template.$file); if($file) { foreach ($array as $key => $val) $file = str_replace('{'.$key.'}', $val, $file); echo $file; } else { echo 'File '.$file.' doesn\'t exist'; } } public function render($template) { ob_start(); include $template; echo ob_get_clean(); } } functions.php function page_header($page_title) { global $date_time, $template, $settings, $lang, $config, $user; $css_link = $template->template.'main.css'; $board_logo = '<img src="'.$template->template.'images/'.$settings['board_logo'].'" alt="'.$settings['board_name'].'" />'; $offset = $date_time->getOffset(); $curr_time = $date_time->getTimestamp(); $time = $curr_time - $offset; $template->board_name = $settings['board_name']; $template->render($template->template.'html/header.php'); } index.php page_header($lang->index);
  19. also when i use: <p id="name"> <?php echo $this->board_name; ?> </p> i get the error: Fatal error: Using $this when not in object context
  20. thanks for the tips. but say i have a tpl file which has about 30 or so <?php echo $this->xxxx; ?> in the php file i would be doing: $v->xxxx = 'x'; $v->x = 'xxxx'; and so on for as many i need to define. is there a faster or better way?
  21. somehow you made it sound so simple. thanks for the help. i dont understand half of the things phpbb does behind the scenes so i stopped learning from their code. this is a big help. thanks
  22. did you remember to include session_start(); at the top of every page that uses this session?
  23. i had wanted to do it the second way: <div class="foo"><?=$foo?></div> but that would throw an undefined variable($foo) error. or am i mising something?
  24. you want to set all the activated fields to one via phpmyadmin?
  25. the current way i display a page on my site is like this i have the php file which takes the contents onf a html file and replaces kets in curly braces with variables the php file $template->replace(array('SITE_NAME' => $site_name),'header_file'); the html file <title>{SITE_NAME}</title> everything runs smoothly until i come to an if statement. I want to display the word login only if no user is logged in. If they are then display their username.(just an example) one way to overcome this is: the php if(isset($_SESSION['logged_in'])) { $user_name = $user->user_name_nl; $user_avatar = $user->avatar; $user_group = $user->group; } else { $user_name = 'Login'; $user_avatar = ''; $user_group = ''; } $template->replace(array('USERNAME' => $user_name, 'AVATAR' => $user_avatar, 'GROUP' => $group),'header_file'); the problem is that the username opens a menu once clicked and if i just did this then if they werent logged in it would display login but it would also open the same menu and all the keys would have to be replaced with ''. now obv i cant include if statements in a html file so does anyone have any ideas or advice? i know phpbb includes the if statements in the html file between comment tags and somehow the same file appears in the cache folder as a php file with the comments stripped so the php code becomes active. but ive looked at how they do it and it just confuses me. Thanks
×
×
  • 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.