Jump to content

VBAssassin

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

VBAssassin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Oh the memories! Let me just explain a little about my site, since this will all become relevant in a minute. Also, you can see it's quite large, though not really huge (over 100,000 lines of code) by checking it out: http://www.coderprofile.com/ First of all, it was entirely procedural. But that soon started too become to much work to update. It kept meaning complete re-writes and/or features being held back. Then i started learning more OOP. So i converted a few things from procedural to objects. Such as the bbcode system,and thumbnails of images, etc. These were pretty independent classes. Then i decided, i want to learn moooooreee... so i got some more books such as PHP Patterns, Objects and Practice (something like that) and some other books about OOP concepts and some UML books (designing them out in UML is a god send, also helps you understand what the books are on about). I also have the gang of four book (design patterns) which is good. They state things like "choose composition over inheritance" and other such tips. You learn the design patterns and as you learn them, they show you "good design" as well. I don't quite understand some of the patterns, but from the ones i do understand like the factory pattern... well... what can i say... i wish i had learn them years ago! They have simplified so much code! Then your ready to really start coding in OOP especially when you can modal them in UML, you understand the difference between aggregation, composition, generalization, etc. A lot of "newbies" (and myself included at the time) tend to inherit everything! This simply produces a mess! Also, learn what packages are (the concept is useful an organize them in to folders aka packages on the server). Read as many OO articles as you can... even if you already understand it... read it again! Eventually... after just a few months you will start thinking in proper OO design ;-) I would also suggest you invest in some books: amazon.com Kind regards, Scott
  2. I have no idea what the heck your on about? Please explain further. I'm somewhat very experienced with creating "profile" sites, the best one i'm doing is http://www.coderprofile.com/ So i'm sure i can help you if you explain a little clearer what it is your trying to do. Kind regards, Scott
  3. Wew! I wasn't expecting all that code and all those files! lmao. Since your going to be working with text files for data, you should get very familiar with serialize and unserialize. Can save a lot of manual parsing. Here is how you should layout your guest book: libs/functions.php - stores all your main functions content/guest_book.php database/index.php database/users/username-password.php database/posts/posts.php You will have to create users manually at the moment by just creating a new file in the format username-password.txt which is more efficient than saving those two details in the file itself (else all the files need to be opened to check for users and duplicate usernames etc). use file_get_contents() and file_put_contents() if you are using PHP5 (much easier than fopen, etc). When a user posts a message in the guest book ask for there username and password with their message. If the username and password file exists, then they are ok to post... then simply add the message on the end of posts.php To view the posts, just use get_file_contents() on the posts.php file. Make sure you put an index.php file in the database/users/ folder to prevent people seeing a directory listing of the users folder and seeing everyones username and password. Anyway... gota get back to work now... this distributed PHP framework is a pain. Kind regards, Scott P.S. Here is an example of a simply page hit counter that uses the file system to save the total hits, instead of a database: http://www.coderprofile.com/networks/source-codes/328/simple-hit-counter-v13
  4. Haha, you never said that (or did you?)... anyway... thats what GROUP BY is for ;-) SELECT COUNT('A1') FROM `answers` WHERE `A1` = '50' OR `A1` = '75' OR `A1` = '100' GROUP BY `A1`; Try that. Kind regards, Scott I said the number of answers of each, but i guess I wasnt very clear I tried that, but I dont think it will work as: it doesnt return empty rows for the options where answer to count = 0 and it doesnt label them. e.g.: SELECT COUNT('A1') FROM `answer` WHERE `A1` = '50' OR `A1` = '75' OR `A1` = '100' GROUP BY A1 gives: COUNT( 'A1' ) 2 2 Oh... this will return data showing which ones have X amount SELECT `A1`, COUNT('A1') FROM `answer` WHERE `A1` = '50' OR `A1` = '75' OR `A1` = '100' GROUP BY `A1`; If it don't show results with 0, then just make a php script to sort that out ;-) Kind regards, Scott
  5. Haha, you never said that (or did you?)... anyway... thats what GROUP BY is for ;-) SELECT COUNT('A1') FROM `answers` WHERE `A1` = '50' OR `A1` = '75' OR `A1` = '100' GROUP BY `A1`; Try that. Kind regards, Scott
  6. lmao... then once you have done whats on that (after it teaches you how to build a login page lol)... just add: header('location: where/ever/your/profile/page/is'); and your done... You should probably know, i'm creating a profile site (taken me 1 and a half years to get to where it is) and my profile on that site is: http://www.coderprofile.com/coder/VBAssassin I assume that's the sort of thing you mean by "profile" site? Kind regards, Scott
  7. Don't ever use COUNT(*)!!! It pretty much forces table scans! Not good. Anyway... SELECT COUNT('A1') FROM `answers` WHERE `A1` = '50' OR `A1` = '75' OR `A1` = '100'; Kind regards, Scott P.S. You need an index on the A1 field.
  8. Looking at that, your comfortable working with JavaScript. I would suggest you now look into using a JS framework such as jQuery or Prototype. http://www.prototypejs.org/api/ajax/request Looking at your code, your just trying to post a form... and no bothered about the return data. In which case you can do it like this. Change <select name="warpx"> to <select id="warpx" onclick='javascript:send_it();'> and then add this js code function send_it() { new Ajax.Request('/url/here/of/where/to/post/it', { method: 'post', parameters: { warpx: $('warpx').value } }); } I haven't tested it though, so chances are there will be some syntax errors or something or other... but thats most of the code you should need anyway to make a simple Ajax POST request. Oh, and you will have to install the prototype framework, add this to the head part of the html: <script src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js' language='javascript' type='text/javascript'></script> Kind regards, Scott
  9. This is a huge subject and too general for anyone here to really reply to. Try google or something like this: http://www.phpeasystep.com/workshopview.php?id=6 Kind regards, Scott
  10. Hi ya, Are these code snippet showing aggregation or composition? Example: <?php class poster { } class wall { function render_poster(poster $poster) { } } $poster = new poster(); $wall = new wall(); $wall->render_poster($poster); ?> Example 2: <?php class poster { } class wall { private $posters = array(); function add_poster(poster $poster) { $this->posters[] = $poster; } } $poster = new poster(); $wall = new wall(); $wall->add_poster($poster); ?> Notice that the second example is NOT being passed by reference (or does PHP5 auto pass by reference unless you use a clone statement or put & in the methods parameter list?). I think i know what i would class them as in my head, but just want your opinions to make sure i'm correct, otherwise, i'm going to be asking some more questions if i'm wrong :-D Kind regards, Scott
  11. Hi ya, Something that's bugged me for a while now is is it better to use www. or miss it off? Looking at it from both a SEO standpoint and a visual standpoint. Kind regards, Scott
  12. Hello, Your main topic content above didn't make much sense to me, so i'm gonna go by your topic title "Submit value only if checkbox is ticked". Basically, you have two options (server side, client side). Client side will require some javascript: <form onsubmit='javascript:if (document.getElementById('id_of_checkbox_here').checked == false) { return false; } ;'> Server side (PHP): if (isset($_POST['checkbox_name_here'])) { //code here if the checkbox was ticked } else { //code here if the checkbox was NOT ticked } Hope that helps. Kind regards, Scott
  13. Haha, this brings back some memories! I started by saving votes (and comments, etc) all in separate tables... bad idea. Save them in 1 table and simply differentiate them using an enumeration. Then simply write a class to handle the votes system. Save a timestamp with each vote so votes can be removed after 24 hours ;-) I'm actually upgrading my voting system to "reviews" :-) Kind regards, Scott
  14. One way around it is to dynamically change the names of the fields sent. This confuses the macros because each time they try and fill in the form, the names and id's etc of the fields it's supposed to access change! Meaning it's then bust. It's a pain to implement dynamic names though, such as: Page Hit 1 <input name='dsafd'> Page Hit 2 <input name='2133dsas'> Page Hit 3 <input name='a8s7sjd'> Since the real names have to saved as well: <input type='hidden' name='_a8s7sjd' value='title' /> Once the form is sent, your post data is scanned for all the names beginning with _ (these for a hash, or in php, associative array). You then lookup each of the dynamic names in the table to work out what data is what from the dynamic form. This will prevent your script from getting confused, but not the macro script (except macro scripts that automate mouse movements and clicking etc but then you have to give up your mouse while the macro runs). Kind regards, Scott
  15. [quote author=Jenk link=topic=110890.msg450747#msg450747 date=1160616785]Constants break encapsulation.[/quote] Not always... [code]<?php         class messages {                 const TYPE_ERROR = 1;         const TYPE_CONFIRM = 2;                 function add_message($message, $type = TYPE_ERROR) {                     }     }         //normal use     $message = new messages();     $message->add_message("Well done!", messages::TYPE_CONFIRM);     $message->add_message("Warning though, don't do this again", messages::TYPE_ERROR);     ?>[/code] Source: http://www.coderprofile.com/networks/discussion-forum/1694/is-there-a-name-for-this Kind regards, Scott
×
×
  • 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.