-
Posts
902 -
Joined
-
Last visited
-
Days Won
9
Everything posted by doddsey_65
-
that shows how tired i am, its supposed to be an update query. $db = db_pdo::$instance; switch($method) { case 'personal': $sql = "UPDATE ".TBL_PREFIX."users_profile SET p_real_name = :real_name, p_location = :location, p_gender = :gender, p_dob_day = :day, p_dob_month = :month, p_dob_year = :year, p_website = :website, p_occupation = :occupation"; $sth = $db->prepare($sql); $sth->execute(array( ':real_name' => $data['real_name'], ':location' => $data['location'], ':gender' => $data['gender'], ':day' => $data['dob_day'], ':month' => $data['dob_month'], ':year' => $data['dob_year'], ':website' => $data['website'], ':occupation' => $data['occupation'], ) ); break; }
-
I have a page which updates the database when the user submits the data. This page has multiple inserts, some of which are empty. what is the best way to prevent clearing data? for example i have this query: switch($method) { case 'personal': $sql = "INSERT INTO ".TBL_PREFIX."users_profile (p_real_name, p_location, p_gender, p_dob_day, p_dob_month, p_dob_year, p_website, p_occupation) VALUES (:location, :gender, :day, :month, :year, :website, :occupation)"; $sth = $db->prepare($sql); $sth->execute(array( ':location' => $data['location'], ':gender' => $data['gender'], ':day' => $data['dob_day'], ':month' => $data['dob_month'], ':year' => $data['dob_year'], ':website' => $data['website'], ':occupation' => $data['occupation'], ) ); break; } if the database column "occupation" contains information but the input is empty then it would replace the info in the database. So what is the best way to prevent this? i know i could use if(empty($data['occupation'])) and build an sql query on loads of if statements to check each input. Is that best? NB. this is example code, most inputs will contain data pulled from the database. This is only relevant for purposely empty inputs like password and secret answers.
-
thanks. I am still working on the user center but i will be uploading the files in the next few hours.
-
you have all of the info you need there, just extract the browser name from the string. Becareful however as chrome uses the same webkit as safari. Here is some old code of mine i managed to dig out. Im sure you could put it into a function of some sort: if (strstr($agent,"Firefox/3")) {$br = "Firefox 3";} if (strstr($agent,"Firefox/2")) {$br = "Firefox 2";} if (strstr($agent,"Firefox/1")) {$br = "Firefox 1";} if (strstr($agent,"Phoenix/")) {$br = "Phoenix (Mozilla lite)";} if (strstr($agent,"MSIE 5")) {$br = "IE 5";} if (strstr($agent,"MSIE 6")) {$br = "IE 6";} if (strstr($agent,"MSIE 7")) {$br = "IE 7";} if (strstr($agent,"MSIE 8")) {$br = "IE 8";} if (strstr($agent,"Netscape6/6")) {$br = "Netscape 6";} if (strstr($agent,"Opera")) {$br = "Opera";} if (strstr($agent,"Opera") and strstr($agent,"Version/10")) {$br = "Opera 10";} if (strstr($agent,"Opera") and strstr($agent,"Version/9")) {$br = "Opera 9";} if (strstr($agent,"Chrome")) {$br = "Chrome";} if (strstr($agent,"Chrome") and strstr($agent,"Chrome/5")) {$br = "Chrome 5";} if (strstr($agent,"Safari/")) {$br = "Safari";} if (strstr($agent,"Safari/") and strstr($agent,"Version/5")) {$br = "Safari 5";} if (strstr($agent,"Safari/") and strstr($agent,"Version/4")) {$br = "Safari 4";} if (strstr($agent,"Safari/") and strstr($agent,"Version/3")) {$br = "Safari 3";} if (strstr($agent,"SeaMonkey/") and strstr($agent,"Gecko")) {$br = "SeaMonkey";} i wouldnt reccoment using this code as is though. its from about a year ago when i was less experienced
-
im getting the double colon error on this line: if(logged_in($user::$data['u_uid'])) $user is defined as new sessionsClass and $data is a public static variable which holds all the user information. So why am i getting this error? it works fine locally.
-
i changed the sql to $sql = "SELECT * FROM ( SELECT COUNT(*) as forums FROM ".TBL_PREFIX."forums AS f UNION SELECT COUNT(*) as topics FROM ".TBL_PREFIX."topics AS t UNION SELECT COUNT(*) as posts FROM ".TBL_PREFIX."posts AS p)"; but it throws the same error
-
that wouldnt make any difference
-
im trying to get the total forums, topics and posts from 3 different database tables named respectivly. I then need to add the results to an array. I have tried the following: $sql = "SELECT sum(f.forums), sum(t.topics), sum(p.posts) FROM ( SELECT COUNT(*) as forums FROM ".TBL_PREFIX."forums f UNION SELECT COUNT(*) as topics FROM ".TBL_PREFIX."topics t UNION SELECT COUNT(*) as posts FROM ".TBL_PREFIX."posts p)"; $result = $db->query($sql) or die($db->printError($sql)); $row = $result->fetch(PDO::FETCH_NUM); $stats['forums'] = $row['forums']; but i get the following error: Every derived table must have its own alias Any advice?
-
i thought so so i did this instead: public function loadFile($file) { $include = dirname(dirname(__FILE__)).'/languages/'.self::$lang.'/'.$file.'_lang.php'; if(file_exists($include)) { include $include; //var_dump($l); return $l; } else { echo 'File does not exist'; return false; } } but still get the same error
-
i have a language class like so: class languageClass { public static $lang; public static function setLang($lang) { self::$lang = $lang; } public static function getLang() { include(dirname(dirname(__FILE__)).'/languages/'.self::$lang.'.php'); return $lang; } public function loadFile($file) { $include = dirname(dirname(__FILE__)).'/languages/'.self::$lang.'/'.$file.'_lang.php'; if(file_exists($include)) { include $include; } else { echo 'File does not exist'; } } } so i include a language file within index.php like this: $lang->loadFile('common'); common_lang.php has an array like so: $l = array( 'HELLO' => 'hello', ); but when i try to echo $l['HELLO'] in the index.php file it says variable $l is undefined. But the language script includes the file where it is defined. If i include the file within index.php then everything works however
-
could it be then the inclusion of html files? for example, to return a list of the forums i run code which returns one html file and loop it for however many forums there is. example of the included file: {FORUM_NAME} then i loop to render the forum name of each forum. Could this be it since some of the html files which are looped consist of around 200 lines of html.
-
in my code i use preg_replace to replace this in an html file <asf: if 1 = 1> to this in the php file <?php if(1 = 1) { and the code i use is: preg_replace('|\<asf: if (.*?) (.*?) (.*?)\>|si','<?php if(\\1 \\2 \\3) {',$content); however if the html file contains <asf:if 1 = 1> notice the missing space after the colon. The preg statement doesnt work. Is there a way to do it regardless of if there is a space there or not?
-
if i remove the preg replace several needed things wont load and therefore break the site.
-
My site runs quite slowly compared to others and im wondering if its the use of preg_replace in my template class. For example in my html page i would have [$root] which would be replaced by the template class using preg replace to the document root. This is just an example, i have loads more rules which replace stuff like that. So is preg_replace slow or are there other reasons why my site is slow?
-
on the forum im making, when viewing a post, i run several queries to get all of the data i need. Unfortunatly this means 19 queries in total(some are general queries and some just relate to the page). some of these queries are simple selects, which only get 1 or 2 peices of info. my question is what is the average limit of queries per page i should go for? is 19 okay if they are small queries?
-
ive amended the code a bit and the array is populated but still with only one attachment if($row[$key]['p_pid'] != $pid) { $pid = $row[$key]['p_pid']; $post[$pid] = $row; $post[$pid]['attachments'] = array(); } if(!empty($attachment_name)) { $parts[$key] = explode('.',$row[$key]['a_name']); $size[$key] = $row[$key]['a_size']; if($parts[$key][1] == 'jpg' || $parts[$key][1] == 'jpeg' || $parts[$key][1] == 'png' || $parts[$key][1] == 'gif' || $parts[$key][1] == 'bmp') { $post[$pid]['attachments'][] = '<div class="post_attachment"><a href="'.$this->vars['config']['asf_root'].'attachments/'.$row[$key]['a_name'].'"><img class="attachment_image" alt="" src="'.$this->vars['config']['asf_root'].'attachments/'.$row[$key]['a_name'].'" /></a><p class="attachment_description">'.$row[$key]['a_description'].'</p><p class="attachment_size"><b>Size: </b>'.$size[$key].'kb</p></div>'; } else { $post[$pid]['attachments'][] = '<div class="post_attachment"><p class="attachment_description">'.$row[$key]['a_description'].'</p><p class="attachment_size"><b>Size: </b>'.$size[$key].'kb</p></div>'; } } //var_dump($post[$pid]['attachments']); foreach($post[$pid]['attachments'] as $attachment) { $list .= $attachment; }
-
ive had to modify it a little since im using PDO and a foreach loop instead of a while loop but i get an empty result on the var_dump(). $post_query = "SELECT t.*, p.*, u.*, a.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) JOIN ".TBL_PREFIX."users u ON (p.p_poster = u.u_username) LEFT JOIN ".TBL_PREFIX."post_attachments a ON (a.a_pid = p.p_pid) WHERE t.t_name = '$t_name' GROUP BY p.p_pid ORDER BY p.p_time_posted ASC"; $execute = self::$instance->query($post_query) or die(self::$instance->printError($post_query)); $row = $execute->fetchAll(); $attachments = array(); $pid = ''; foreach($row as $key => $value) { $attachment_name = $row[$key]['a_name']; unset($attachment_name); if($row[$key]['p_pid'] != $pid) { $pid = $row[$key]['p_pid']; $post[$pid] = $row; $post[$pid]['attachments'] = array(); } if(!empty($attachment_name)) { $parts[$key] = explode('.',$row[$key]['a_name']); $size[$key] = $row[$key]['a_size']; if($parts[$key][1] == 'jpg' || $parts[$key][1] == 'jpeg' || $parts[$key][1] == 'png' || $parts[$key][1] == 'gif' || $parts[$key][1] == 'bmp') { $post[$pid]['attachments'][] = '<div class="post_attachment"><a href="'.$this->vars['config']['asf_root'].'attachments/'.$row[$key]['a_name'].'"><img class="attachment_image" alt="" src="'.$this->vars['config']['asf_root'].'attachments/'.$row[$key]['a_name'].'" /></a><p class="attachment_description">'.$row[$key]['a_description'].'</p><p class="attachment_size"><b>Size: </b>'.$size[$key].'kb</p></div>'; } else { $post[$pid]['attachments'][] = '<div class="post_attachment"><p class="attachment_description">'.$row[$key]['a_description'].'</p><p class="attachment_size"><b>Size: </b>'.$size[$key].'kb</p></div>'; } } var_dump($post[$pid]['attachments']); }
-
im struggling to get this working or to understand the code behind it. could you perhaps give an example?
-
this is how i build the attachement list for a post: if(!empty($row[$key]['a_name'])) { $parts[$key] = explode('.',$row[$key]['a_name']); $size[$key] = round($row[$key]['a_size']/1024, 2); if($parts[$key][1] == 'jpg' || $parts[$key][1] == 'jpeg' || $parts[$key][1] == 'png' || $parts[$key][1] == 'gif' || $parts[$key][1] == 'bmp') { $attachment_list .= '<div class="post_attachment"><p class="attachment_name">'.$parts[$key][0].'</p><a href="'.$this->vars['config']['asf_root'].'attachments/'.$row[$key]['p_poster'].''.$row[$key]['a_name'].'"><img class="attachment_image" alt="" src="'.$this->vars['config']['asf_root'].'attachments/'.$row[$key]['p_poster'].''.$row[$key]['a_name'].'" /></a><p class="attachment_description">'.$row[$key]['a_description'].'</p><p class="attachment_size"><b>Size: </b>'.$size[$key].'kb</p></div>'; } else { $attachment_list .= '<div class="post_attachment"><p class="attachment_name">'.$parts[$key][0].'</p><p class="attachment_description">'.$row[$key]['a_description'].'</p><p class="attachment_size"><b>Size: </b>'.$size[$key].'kb</p></div>'; } $array['attachment_list'] = $attachment_list; } else { $array['attachment_list'] = null; } is that what you mean?
-
so what would you suggest? running a query within the foreach loop of the result set to get the attachments?
-
im using a query to pull all posts, join the parent topic, join the user table on the poster of the post and join the attachments table on the pid of the attachment: post_query = "SELECT t.*, p.*, u.*, a.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) JOIN ".TBL_PREFIX."users u ON (p.p_poster = u.u_username) LEFT JOIN ".TBL_PREFIX."post_attachments a ON (a.a_pid = p.p_pid) WHERE t.t_name = '$t_name' GROUP BY p.p_pid ORDER BY p.p_time_posted ASC"; then i echo the attachment if the post has any. unfortunatly it only displays one attachment name regardless of how many it has. if i remove the group by in the query then i get a duplicate of the post for how ever many attachments it has. Any one know what im doing wrong?
-
ive done some testing and narrowed it down to the render method. But i use this method on all of my pages with no problems. So here is the method for you to look at, as you can see, no loops. public function render($file_name, $array, $sidebars = 'show') { if(file_exists($file_name.'.php')) { include($file_name.'.php'); } else { session_start(); $array['sidebars'] = $sidebars; $array['board_subtitle'] = $this->vars['settings']['board_sub_name']; $array['template'] = $this->vars['config']['asf_root'].$this->templatePath; $array['board_title'] = $this->vars['settings']['board_name']; $array['user_real_name'] = $this->user['u_real_name']; $array['user_group'] = $this->user['g_title']; $array['avatar'] = userClass::createAvatar($this->user['u_avatar']); $array['redirect'] = $this->asf->getRedirect(); $array['root'] = $this->vars['config']['asf_root']; isset($_SESSION['logged_in']) ? $array['logged_in'] = 'yes' : $array['logged_in'] = 'no'; $content = file_get_contents($this->templatePath.$file_name.'.tpl'); $cache_file = './cache/'.$file_name.'.php'; @$content = preg_replace('|\[\$(.*?)\]|e', '$array["\\1"]', $content); $content = preg_replace('|\<asf: if (.*?) (.*?) (.*?)\>|', '<?php if(\'\\1\' \\2 \'\\3\') { ?>', $content); $content = preg_replace('|\<\/asf: if\>|', '<?php } ?>', $content); $content = preg_replace('|\<asf: else\>|', '<?php } else { ?>', $content); $content = preg_replace('|\<asf: sidebar\[(.*?)\]\>|e', '$this->renderSidebar("\\1")', $content); $open = fopen($cache_file, 'w'); fwrite($open, $content); include('./'.$cache_file); } }
-
I have a weird problem. I have just made a new file but for some reason its taking about 2 mins to load it. I found out why its taking this long. The file renders a header and then the content, then the footer. However this particular file renders the header on a loop(which isnt what its supposed to do). When it does start loading the actual file the header shows up around 20 times. The general code is the same as other files since i have just started it and every other page works. Its nothing to do with htaccess as i thought it could be because i have removed the rewrite rule and did the normal url query line, but the same thing happens. This is the whole content of the file: <?php /* ASF A Simple Forum * (c) ASF A Simple Forum 2010 - 2011 * * @licence http://www.asimpleforum.co.uk/licence * * $page new_post.php * $author Carl Markham * $created 10/06/2011 */ define('IN_ASF', true); include('./includes/initialize.php'); if(isset($_GET['method'])) { $method = $_GET['method']; $name = $_GET['name']; if($method == 'post') { $crumbs = array( '.' => 'Board Index', $config['asf_root'].'new_post/post/'.$name => 'New Post - '.$name, ); $template->outputHeader('main_header','New Reply - '.$name,'jQuery_tools,jquery.timeago', 'main', $crumbs); $array['topic_name'] = $name; } $template->render('new_post', $array, 'show'); $template->outputFooter(null); } Im not visiting this file from a link, just adding the url to the address bar directly. the render function and outputHeader and outputFooter functions just call other files to be included, which is what i do with other scripts(they work). So anyone know why this file appears to get looped so many times? Thanks
-
i need to color the username of user to display which group they belong to on my forum. i do this by running a query which gets their group and joins the group table to get the color. I then return the link which is colored accordingly. However this means a query for every username that is displayed on the screen. I did this the same way on the old version of the forum and it seemed fine. My query count would stay at around 14 regardless of how many users were on screen. However in this new version i am getting around 25 queries because of this, most of them getting the color for every user. is there a better way to do this?