Jump to content

eevan79

Members
  • Posts

    240
  • Joined

  • Last visited

    Never

Everything posted by eevan79

  1. Yes. I wrote it in first post. Now I want to write variable. part of content of config.php $topics_per_page = '10'; $blah_blah = '5'; ...etc Now want to write new value (for example in $topics_per_page). That is not a problem. Get variable...and than write another value. Problem is if I have: $topics_per_page = '10'; (instead of $topics_per_page = '10'; - note white space). Problem with getting value is solved (ignoring white space between =), but when I write value if I have one more empty space between variable, '=' and value it wont work. Hope now its clear.
  2. Thanks ken. Thats working. But as you see from previous function I use explode('=', trim($line) ) to eliminate empty spaces between variable and value. I already tried similiar code as you suggest, but it wont working if I have (example): $topics_per_page = '5'; only will work in this case: $topics_per_page = '5'; Not big deal, but still want to eliminate this.
  3. I wrote function to get value of specific variable in file: function get_lang_of($name) { $lines = file("config.php"); foreach (array_values($lines) AS $line) { list($key, $val) = explode('=', trim($line) ); if (trim($key) == $name) { $val = convEnt($val); return $val; } } return false; } and call it with get_value_of('$topics_per_page'); In file config.php I have: $topic_per_page = "10" and with this function I get 10. I need same function (method) but to write. example: write_value_of('$topics_per_page','5'); Tried but failed. Wanted to avoid white spaces: $topics_per_page = '10' and $topics_per_page = '10' Tried something like this (not function): $file = "config.php"; $file_contents = file_get_contents($file); $fh = fopen($file, "w"); $file_contents = str_replace('$topics_per_page = \'10\'','$topics_per_page = \'5\'',$file_contents); fwrite($fh, $file_contents); fclose($fh);
  4. ( link to my profile - http://avs-demo.iz.rs/testforum/eevan.html ) This ismy first php script about small forum software. Main goal is tomake forum script with many features and less size (about 200kb,100kb zipped). Some features: WYSIWYG lightweight editor Ajax check usernames Template system Captcha (for guests, on registration...) Allow/dissallow smiles in post, bad word filter, topics per page, posts per page, different time formats... Link: http://brevisbb.iz.rs un: phpfreaks pw: phpfreaks Feel free to test this for weak spots, debug... Be critical because this is my first php script... Ivan edit: updated link at OP's request ~ CV
  5. Ok. All clear. I put link to my profle on my profile of my website. Thats my mistake. I'll upload than that file. Hope thats ok. Delete/lock this topic or whatever.
  6. Ok. I read it again...and still dont know what is wrong. Here is content of my deleted post: And what is wrong with this?
  7. Hello, I like this site, cause always got answers quickly. Very good community. But just wonder why is my post deleted in Beta test forum? I wrote post about my forum script and wanted to expirienced peole look, debug and test for weak spots (because its my first php script)... and post is just deleted. Also I read rools before posting.
  8. I wrote function that return value of specific variable in config file and I can change values and write file via admin panel. What is best way to protect file and what file permission I need (750)? Should I first change the permision to write file, than change values, and back permission to read only?... or there is another better solution? I do not know how this should work because I'm working on localhost.
  9. Now its working. Code is include("../config.php"); I just added "(" and ")"... :-\ include("../config.php");
  10. I already tried that: include($_SERVER['DOCUMENT_ROOT']."./config.php"); and include($_SERVER['DOCUMENT_ROOT']."config.php"); and many other combinations...but it wont work. That path is on/from localhost. Didnt tested online. I need to locate path automaticly if its possible. For example to get working directory and go back one level. Is it possible (like in java or c++)?
  11. No such file or directory...\adm\admin.php on line 2 I use this code: include($_SERVER['DOCUMENT_ROOT']."../config.php"); How to back one level?
  12. How to include file from subdirectory? I have tried include '../config.php'; but got error selecting database. Also tried include($DOCUMENT_ROOT."../config.php"); but same result. For example, I have "root/admin" directory, and cant connect (from "/admin" dir) to database config.php which is in root.There are also other files to include.
  13. I need help for updating last topic from categories. Problem is that first must check if there is latest topic from subcategory. Table for updating: categories Here is my script UPDATE ".$table_prefix."categories SET cat_last_post_subject='".$tsubject['topic_subject']."', cat_last_poster_name= '".$userposted['user_name']."', cat_last_poster_id=".$userposted['user_id'].", cat_last_post_date = NOW(), cat_last_topic_id = ".$tsubject['topic_id']." WHERE cat_id=" .$tsubject['topic_cat']." But first I must check if cat_id have cat_parent. If true than update that post ifcat_last_post_date is newer than first. To explain what is cat_parent: If cat_parent is 0 than thats root category. If cat_parent have number, that number is ID of root category. For example if there is filed cat_id 10 and cat_parent 3, that means category with cat_id 3 have subcategory with cat_id 10... How to check if there is newer post in subcategory than root? EDIT: to make more clear. First must be select recent post (considering cat_id and cat_parent). SELECT cat_id, cat_name, cat_description, cat_icon, cat_parent, cat_child, cat_child, cat_last_post_subject, cat_last_topic_id, cat_last_poster_name, cat_last_poster_id, cat_last_post_date FROM categories WHERE cat_id = ".$row['cat_id']." ORDER BY cat_last_post_date DESC LIMIT 0,1 But if it have cat_parent > 0 (have subcategory), check/select that cat_id (cat_parent) for recent post. That means post in subcategory is with recent date than category.
  14. This issue is more related to MySql. Can moderator move this topic there? By the way, here is example of script - http://avs-demo.iz.rs/testforum/ I optimized script now and get less queries than before. Only on index page I get more than 20 queries.
  15. if(!$query) {echo $l_cat_cant_display;} Thanks mjdamato. This is "echo" after mysql_query: The categories could not be displayed, please try again later. But you point me in right direction. I read all articles about LEFT JOIN but still dont have enough expirience to use this queries with many conditions. Now I realize that this is topic for mysql section. Anyway, with perfect query SELECT I'll get queries as much as categories when fetching data. That's not big deal, but just wonder how scripts like phpbb or smf have max 5-10 queries per page? I looked into source and as I can see solution is in caching data. Thats impossible to get 5 queries where is about 30 categories and 20 subcategories at one page (with all data about users, topics,categories, sub-categories, dates)...or I maybe wrong?
  16. Thanks. This serialize method for caching makes me headache . I understand how to write serialized data, but dont realize how to return data in strings. For example, I serialize category, ID, name, parent, child. And dont understand how to pull this data into strings $catID, $catName, $catDescription etc...but thats another topic.
  17. I dont have performance or lag issues. Just want to reduce unnecessary queries. Because if there are (for example) 30 categories with 30 sub-categories there will be more than 100 queries per page load (index) . I like idea for caching categories instead of using mysql queries. What is best way to cache categories into file? For now I use following scipt: if (file_exists('./cache/'.md5($_SERVER["SERVER_NAME"]).'.php')) { $var = file('./cache/'.md5($_SERVER["SERVER_NAME"]).'.php'); foreach($var as $k => $v){ echo '<br />'.$k.' is '.htmlentities($v); //...reading categories } } (if there is no file, data will be obtained from the mysql database).
  18. Thanks -cb-. Thats very usefull. Thats nice solution. I must learn how to cache index page . But that will not update last topic for that category. EDIT: I just found usefull link about caching pages (maybe outdated): http://simonwillison.net/2003/May/5/cachingWithPHP/ and than I just need to perform queries for last topic on that category...
  19. Thanks for reply. For each category and another for topics in that category. Thats option in config.php - subcategories_on_index ... Here is my index.php in attachment. Please note that I am very begginer with php, but learning quickly. ^^ EDIT: Screenshot of category table. [attachment deleted by admin]
  20. How to reduce queries with php? I'm working on script where is about 42 queries on index page, and max 10 queries on topic and "read-posts" page. I put simple counter where is mysql_fetch_assoc and on index page there are 2 while loops - for categories and posts. Result is 42 queries (if I count subcategories, 15 queries if not). I think thats a lot. Here is structure of my index page: First I select all from categories (I need them all) - ID, Name, Description, Icon, Parent, Child and JOIN LEFT topics table. In while loop I render html tables - one row for each category. If I have enables to display subcategories I have in same loop another while loop (before html output) where I select all categories table where cat_parent field >0 (that means if there are sub-categories) . And finally I have last while loop where are html output for topics in category ID. Result is 15 queries without enabled option to display sub-categories and 42 with that option. And thats result for 6 categories with 5 sub-categories. I can not imagine what would happen if there are more categories and sub. How to reduce this queries? There are problem with mysql_fetch_assoc where is few queries per category. More categories more queries. How SMF have only few queries with page where is about 30 topics?
  21. SELECT posts.post_topic, posts.post_id, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.user_name, users.user_last_login FROM posts, users WHERE users.user_last_login > posts.post_date AND users.user_id = ".$_SESSION['user_id']." ORDER BY post_date DESC Search found 0 maches. Script in my second post working, but filtered with php. Can I do this in mysql? For example: I have 2 tables: posts and users. I want to select all posts with newer post_date than users.user_last_login date or select post_date between now() and users.user_last_login??? Cant make this to work (exept with php filtering).
  22. Here is how I solve it. First I select users table $result = mysql_query("SELECT * FROM users WHERE user_id = ".$_SESSION['user_id']."");... $lastvisit_day = strtotime(($row['user_last_login'])) Than I select posts table: $result2 = mysql_query("SELECT * FROM posts WHERE post_date >= NOW() - INTERVAL 30 DAY ORDER BY post_date DESC"); and compare dates with php if ($lastvisit_day < strtotime(($row2['post_date']))) ... Is there better way?
  23. How to compare two date from different tables? For example I want to show new posts (from posts table) till last login (from users table). Here is my code, but it show all posts: $result2 = mysql_query("SELECT posts.post_topic, posts.post_id, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.user_name, users.user_last_login FROM posts, users WHERE users.user_last_login > posts.post_date ORDER BY post_date DESC"); while($row2 = mysql_fetch_assoc($result2))... Here is time formats from tables: post.post_date: 2010-06-28 02:44:25 users.user_last_login: 2010-07-05 02:16:38
  24. Thanks for answer, but that doesnt solve problem. When I write 20 spaces and one character script counts 21 characters. If I write only spaces script doesnt allow to post less than 3 characters. So I can post if I type " 1 ", but not " ". Can I fix this with regex?
×
×
  • 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.