Jump to content

doddsey_65

Members
  • Posts

    902
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by doddsey_65

  1. the goal is to select all topics grouped by the month they were posted in then take the amount in the month and add it to the datay array
  2. not really thats why im asking for help, ive spent hours on this now, ive tried to leave it and move on but i cant, its bugging me too much. The code you pointed out means if the date changes then run the code below.
  3. thanks for the helpful comment
  4. Im trying to get some data from the database so i can add it to a graph. The graph points are generated via $datay which is an array built via the database query. The query pulls all the info from the topics table, if the month of which the topic was created changed it adds a new point to the graph with a value of the amount of topics within the month. Based on my database values: $datay[0] should be 1 $datay[1] should be 4 $datay[2] should be 5 $datay = array(); $datax = array(); $db = db_pdo::$instance; $sql = "SELECT * FROM ".TBL_PREFIX."topics ORDER BY t_time_posted DESC"; $sth = $db->query($sql); $row = $sth->fetchAll(); $count = 0; foreach($row as $key => $val) { $date[$key] = date('m', $row[$key]['t_time_posted']); if(date('m', $row[$key]['t_time_posted']) != $date[$key-1]) { $count++; $datay[] = $count; $count = $key; } $_count = count($row)-$count; $datay[0] = $_count; } unfortunatly i am not getting those results. instead i get $datay[0] = 1 $datay[1] = 1 $datay[2] = 6 This means i should have 8 topics in total, but i have 10. Anyone have any ideas? Its nothing to do with the graph, just the way i am adding data to the datay array. Thanks
  5. It seems so simple but i have spent the best part of 2 hours trying to do this. I want to select all the topics from the database and all of the users, then i want to display the dates of the last 7 days and show how many users registered and how many topics were created on that day like so: 4th Aug 2 topics 1 user 3rd Aug 5 topics 3 Users and so on. Anyone have any tips or can anyone help?
  6. Im trying to use the last 7 days(numerical) in a graph so the x axis would be (from todays date) 28,29,30,31,1,2,3,4. The only thing i could think of is a for loop and setting $i as date('d'). Obviously this didnt work as the second parameter in the loop would be $i< or $i>. But $i could be both. Any ideas?
  7. I have a settings.php file which contains an array like so: $settings['board_name'] = 'A Simple Forum'; $settings['board_short_name'] = 'ASF'; But now i have come to the admin part where these settings can be changed i am wondering if this is the best way of handling settings. When the admin chooses to modify one of these settings i would have to open the file, find the line of the setting they want changing and overwrite that line with the new setting. I could store these settings in the database however, which would mean an easier job of replacing settings. Does anyone have any ideas as to which method is best? or if there are any other methods?
  8. the data is escaped before that point, im not too sure how though lol
  9. ive had a read through google and it seems like the u000a is coming from JSON.stringify function which replaces \n with u000a. As a simple fix i have replaced all u000a's with <br /> when it is outputted to the browser.
  10. you wont be able to test it without registering, sorry. I think it could be json_encode() which is converting new lines to 'u00a'. here is the code to insert to the database: $db = db_pdo::$instance; $data = json_decode(stripslashes($data)); $user = sessionsClass::$data; if(empty($data->post[0]->subject)) { $data->post[0]->subject = 'No Subject'; } if(empty($data->post[1]->content)) { $data->status[0]->error = 'You must supply a message body'; } // sql for post insertion $sql = "INSERT INTO ".TBL_PREFIX."posts (p_tid, p_fid, p_poster, p_name, p_content, p_time_posted) VALUES (:topic_id, :forum_id, :poster, :post_name, :post_content, :time_posted)"; // prepare the sql statement $sth = $db->prepare($sql); // execute the sql statement $sth->execute(array( ':topic_id' => $data->post[3]->topic_id, ':forum_id' => $data->post[2]->forum_id, ':poster' => $user['u_username'], ':post_name' => $data->post[0]->subject, ':post_content' => $data->post[1]->content, ':time_posted' => time() ) )or die($db->printError($sql)); when the form is submitted its contents are processed using: $j('form[name="new_post_form"]').submit(function(e){ e.preventDefault(); var data = { 'post': [ {subject : asf.getInput('subject')}, {content : asf.getInput('post_content')}, {forum_id : '{FORUM_ID}'}, {topic_id : '{TOPIC_ID}'} ] } asf.handleForm(data, './new_post.php?method=add_{METHOD}'); }); this.handleForm = function(data, file, redirect) { data.status = [{ error : '', success : '' }]; dataString = JSON.stringify(data); $j.post(file, { data : dataString }, function(result) { var obj = JSON.parse(result); if(obj.status[0].error) { handleProcess('error',obj.status[0].error); } else { handleProcess('success',obj.status[0].success); if(redirect) { document.location = redirect; } } }); } and then sent to the above php script
  11. i think its probably to do with JSON rather than the php, when i view the JSON response in firebug the u00a is already there
  12. theres nothing wrong with the actual sql otherwise it would have given an error. I am using PDO which is a database abstraction layer
  13. here is the code which inserts the content into the database: $sql = "INSERT INTO ".TBL_PREFIX."posts (p_tid, p_fid, p_poster, p_name, p_content, p_time_posted) VALUES (:topic_id, :forum_id, :poster, :post_name, :post_content, :time_posted)"; // prepare the sql statement $sth = $db->prepare($sql); // execute the sql statement $sth->execute(array( ':topic_id' => $data->post[3]->topic_id, ':forum_id' => $data->post[2]->forum_id, ':poster' => $user['u_username'], ':post_name' => $data->post[0]->subject, ':post_content' => $data->post[1]->content, ':time_posted' => time() ) )or die($db->printError($sql));
  14. okay i have a problem when uploading the script to my live server. Wikipedia throws back an access denied error. Is there any way to get around this?
  15. Everytime i submit text it is sent to the database with new lines being replaced with u00a. Anyone know what causes this?
  16. thanks for the reply. I have managed to do it after some hard work and alot of problems. Firstly the wiki bbcode looks like [wiki]jenson button[/wiki] the function then opens the url http://en.wikipedia.org/wiki/Jenson_button as you can see spaces are automatically replaced with underscores and the first letter is automatically capitalized. The problem is that this page is null because the person who created the page also capitalized "button". Also there was the problem with pages that have no images in the info box. This only became a problem since i wasnt retrieving the full info box but just as far as the image. Well heres the code i used to achieve it. Ive ran a few tests and they all work. The only problem is that it is very slow so if anyone has any ideas on speeding it up then please let me know. function wiki_preview($page) { $info_box = ''; $link = 'http://www.en.wikipedia.org/wiki/'.$page; // if there is no page at the given address then capitalize all // letters. if(!$lines = @file($link, FILE_IGNORE_NEW_LINES)) { $page = ucwords($page); } $link = 'http://www.en.wikipedia.org/wiki/'.str_replace(' ','_',$page); // open the file as an array $lines = @file($link, FILE_IGNORE_NEW_LINES); // if we could open the file if($lines) { foreach($lines as $line_num => $line) { // if this page has an info box if(preg_match('|\<table class=\"infobox|si', $line, $matches)) { // get the lines from the start of the infobox for($i=$line_num; $i<100; $i++) { // if this isnt the first closing td tag then we continue if(!preg_match('|\<\/td\>|si', $lines[$i-1])) { // need to replace the relative image link with an absolute one $info_box .= preg_replace('|\/wiki\/File\:|si', 'http://en.wikipedia.org/wiki/File:', $lines[$i]); } // else we return what we have else { return '<a target="_blank" href="'.$link.'">'.$info_box.'</td></tr></table></a>'; } } } } } // if it couldnt find the page else { return '<div class="infobox">This entry does not exist on wikipedia</div>'; } }
  17. Im trying to set up a unique bb code where the user enters [wiki]george clooney[/wiki]. What i want to do is return the infobox that wikipedia has on the right of its pages. This box is held in a table with class "infobox" so i have been trying to return it, but to no avail. I have tried using $content = stream_get_contents($handle); which returns all of the html for the wiki page, but i dont know how to extract the info box from this. Anyone have any ideas?
  18. Thanks for the comments, unfortunetly i have used the UNIX timestamp for every database date, so i will look into that sql method. Thanks
  19. im building an alert system where all alerts for the current user are listed. What i would like though is for the alerts to be grouped under the date they were added to the database. For example this is how it displays now, its just a list: alert1 alert2 alert3 but i would like it like this: 29th July alert1 alert2 28th July alert3 alert4 alert5 Anyone have any idea how i may go about it? I have a date column(UNIX timestamp) in the database for the alerts but it wouldnt be grouping using the SQL would it?
  20. A while ago i made a search function which worked well, but i deleted it. It used some sql i had never come across before(MODE BOOLEAN) or something like that. Ive been looking through a few search functions on other sites and they seem to always use LIKE, but i think i heard somewhere that this isnt the best thing to use. Is this right? and does anyone know what SQL code i am referring to?
  21. heres a dump of the javascript object if it helps: data 'post' 0 subject => 'test' 1 content => 'content' 2 forum_id => 1 3 topic_id => 1
  22. try it yourself and when youget stuck ask for help and post what you've tried. Users wont just give out code to someone who hasnt at least attempted it.
  23. if you want to supress the notice then place the @ symbol infront of fopen(). although the notice is there for a reason.
  24. i would like some advice on the layout of the post displays. You can view the default one here: http://www.asimpleforum.co.uk/view_topic.php?f=4&t=243 and the second layout is here: http://www.asimpleforum.co.uk/view_topic.php?f=4&t=243&v=bubbles
×
×
  • 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.