Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. The code you provided indeed has some flaws, all fields are for example public which is bad practice as you have no way of applying any validation (and only the User object knows best how it data should look like). Indeed it retrieves the entire row and relevant information from other rows but when you try to abstract you have to retrieve everything as you don't know who will be using it. And to have a great abstraction you need objects to know as little as possible (loose coupling, high cohesion). Like you said "It updates the entire row for any update" is indeed bad and can be easily circumvented by remembering which data has changed, you will however need setters & getters as you can't add code to a class property. Dwight D. Eisenhower once said: "I have always found that plans are useless but planning is indispensable". Good quality software starts with planning, more concrete with a domain model (sometimes accompanied by a sequence diagram to make sure your model makes sense). The domain model is a visual representation of your (current) domain knowledge gained through conversation with the domain expert (your client). Because you have a domain model doesn't mean you need to stick to it after all in Agile development is everything optional (except the code). Your domain model is like the "plans" in the Eisenhower quote useless but indispensable to have gone through. Every pattern was/is build on software design principles (and you should know these by heart) and therefor all components have a high separation of concerns (SoC) and a single responsibility (-principle, SRP). Your value object (VO) is so popular due to it solving the problem, have a clear SoC and SRP, while keeping the model simple (and simplicity should always be your aim, our minds have trouble to picture something complex). The mapper you found in Advanced PHP Programming is a rather simple mapper, more effective mappers are for example an object-relational mapper (ORM) which would translate your database (for example by using a database abstraction layer (DBAL, rewrites queries to match the underlying database)) into objects to use in your application. However I probably can keep going on and on and on .. There is nothing that I told you that you can't find in books, if this subject interests you very much I highly recommend: Applying UML and Patterns [Craig Larman], Domain-Driven Design [Eric Evans], Design Patterns [GoF], and Patterns of Enterprise Application Architecture [Martin Fowler]. These last 2 books are catalogs (pattern catalogs) they list the patterns in a common format to explain it's nature, aka's, and suggest usage.
  2. First I thought you asked about your db structure, then I thought it was about several pages doing one thing, and now your aiming at design patterns? So, what is it your aiming at? domain-modeling? And a VO is a representation of a tuple like for example from a table users (id, username, password, password_salt, email_address) class User { private $id, $username, $password, $password_salt, $email_address; //setters & getters } class UserDAO { public function findByUsername($username) {/*logic here*/return new User($data); } } And something else I don't get is: How come I have to tell you things, you should be telling me? A VO, DAO, ActiveRecord are more then just common in J2EE. They have their own catalogs of design patterns. You could almost say patterns were born in Java.
  3. add a field user_id in your dvd_info table. When you select the DVD's you use: WHERE user_id = ..
  4. The cleaning function I would write as: if (!function_exists('get_magic_quotes_gpc')) { function get_magic_quotes_gpc() { return false; } } function clean($value, $charset = 'ISO-8859-1', $allowed_tags = '') { $value = trim($value); $value = strip_tags($value, $allowed_tags); $value = htmlentities($value, ENT_QUOTE, $charset); $temp = @mysql_real_escape_string($value) ? $value = $temp : $value = get_magic_quotes_gpc() ? $value : addslashes($value); return $value; } The login implementation could be: function validUsername($username) {/*implementation*/} function validPassword($password) {/*implementation*/} function findUserByCredentials($username, $password, $result_type = MYSQL_ASSOC) { $username = clean($username); $password = clean($password); $query = "SELECT id, username FROM users WHERE username = '$username' AND password = sha1( concat( password_salt, sha1( '$password' ) ) )"; $result = mysql_query($query); return false !== $result && mysql_num_rows($result) === 1 ? mysql_fetch_array($result, $result_type) : array(); } function verifyUser($user) { if (!session_id()) session_start(); $_SESSION = array_merge($_SESSION, $user); return true; } define('LOGIN_OK', 1); define('LOGIN_EMPTY', 2); define('LOGIN_INVALID', 4); define('LOGIN_NOT_FOUND', ; function login($username, $password) { $username = clean($username); $password = clean($password); if (empty($username) || empty($password)) return LOGIN_EMPTY; if (!validUsername($username) || !validPassword($password)) return LOGIN_INVALID; $user = findUserByCredentials($username, $password); if (empty($user)) return LOGIN_NOT_FOUND; verifyUser($user); return LOGIN_OK; }
  5. Take a look at http://www.php.net/manual/en/function.md5.php#81708
  6. No as it's one of the requirements for a hash-function. How do you MD5 these password's? Like: WHERE password = md5('$password'); Then your website is in danger as hacker's can use rainbow table's to retrieve a value that will match the MD5 stored in your database and it's best to use salt's like: WHERE password = md5( concat( password_salt, md5( '$password' ) ) ) The hacker now isn't able to use a rainbow table as the retrieved value wouldn't be correct.
  7. Cookies are supported by most (if not all) browsers. Your function will do fine although I would recommend generalizing it more, like: function htmlInput($array, $type = 'hidden') { $html = ''; foreach($array as $name => $value) $html .= "<input type=\"$type\" name=\"$name\" value=\"$value\" />\r\n"; return $html; }
  8. Don't expect to much of Lulu promoting your book, there are too many that's where your website comes in. Promote your book, write your text to make them curious about what they may find inside your book and buy it! Do a read on SEO and copywriting to make your text more compelling, link to (and clearly state that you handle printing through) lulu.com. The reason that you need to clearly state it is because if you don't your visitors become confused, scared and will NOT buy the book. Gain their trust and once the reviews come rolling in you'll probably start to sell even more. And about the price I think it's a fair price if you have put a lot of effort in the research.
  9. I got this: 0: $vargame = 0, $colorgame = "red", $gametrick = 0; 1: $vargame = 3, $colorgame = "green", $gametrick = 1;//elseif ($vargame < 4 && $vargame < 2) 2: $vargame = 6, $colorgame = "green", $gametrick = 2;//elseif ($vargame < 4 .. 3: $vargame = 8, $colorgame = "red", $gametrick = 3;//else 4: $vargame = 7, $colorgame = "yellow", $gametrick = 4;// elseif ($vargame == 8 .. 5: $vargame = 9, $colorgame = "red", $gametrick = 5;// else 6: $vargame = 10, $colorgame = "blue", $gametrick = 6;// elseif ($colorgame == "yellow" ... 7: end The text in comments is what applied.
  10. if (in_array($name, array('dave','thomas','steve')) shorter but I doubt it's faster
  11. That book was published in 2008 (think this still works?), Google changes their algorithm again and again and again and .. at infinitum. Currently Google even employs an algorithm that changes the results based on location, country, preferences, .., weather, .. Just try it, refresh the page (or compare results at home and at work, ..), chances are you get a different result (although the same keywords are used). Read this http://searchengineland.com/36-seo-myths-that-wont-die-but-need-to-40076 (4/15/2010) as it's more accurate then your book.
  12. A few pointers as how I would improve it. I took the term stack literally as you'll notice. It may be best to put the search bar below the signup & learn more. It also may help to add something like Trends (What's hot? What remains hot?). Stackway has great potential it just needs a good brainstorm and a good designer/information architect to expose that potential.
  13. No. That ~70% is market share. If you ever know how Google applies his ranking algorithm, you will be a rich man as that information is worth a lot of money to many SEO firms We all know that Google appreciates content (especially the sort that changes a lot) like all SE do and that's about everything we get to go on. Whenever a user enters a query Google will search for each word in the query (unless they used " whereas it would be considered one word) and looks through your content. The website that matches the most words and has an OK pagerank will rank high followed by the once who have a lower pagerank or a lower word relevancy. For this reason you must always think of "what will the user enter when he looks for my product? website?" Ofcourse this entire paragraph is full of speculation, of how I think Google applies his algorithm (with some knowledge applied from full-text searches) and may in-fact be completely different, who knows? We also "know" that Google is a firm and thus bound to it's end-users (it can not apply things that would decrease the overall experience)
  14. It's better then oldmastercopies but it still lacks a serious usability. And like andrewgauger already told you it would be best to find an agent, write the book and publish it. Use your websites to promote your book. If you don't want to go through all the fuss of finding an agent, convince them, find a publisher who wants to invest in your book, you could use http://www.lulu.com/ you just send them the copy and they will sell if for you. It's easier to convince people to buy your book through an established company then them hoping you will send them something after you received their money.
  15. Google (~70%) only looks at the description meta tag if it thinks it can help. The keywords tag is useless. Yahoo (~17%) had once stated they looked at the keyword tag. Source: http://www.seoconsultants.com/meta-tags/myths/ Source: http://searchengineland.com/36-seo-myths-that-wont-die-but-need-to-40076 Source: http://www.youtube.com/user/GoogleWebmasterHelp alt tags are meant for disabled users Google does not incorporate your alt attributes into their ranking. Has nothing to do with SEO but instead is a good practice. Sure, keep believing that. That's prolly why so many error bloated websites rank high? This is just a good practice towards yourself from having headaches instead of being SEO related.
  16. You need Round-Robin Tournament otherwise if you have an uneven number of players one player will not be able to play as you do not have a competitor for him.
  17. All your pages are to specialized, they do just one thing (paint, reasses, ..) You even have 2 pages that provide the same functionality PaintCarAndShow, PaintCarAndReturn, possibly due to your J2EE background where these would have been methods with an event listener added to. It would be best to give users a form where they can adjust color, mileage, .. all at once. Which will also decrease the number of pages you currently have and increase the usability of your application. Something I noticed is that your database design structure isn't optimal for example: Asset_Tbl (AssetID, TypeID, UserID, Make, Model, Size, Year, Color, Value) Now the below $DB_Result = new db_query("SELECT Make, Model, Year, Color, Value FROM Cars_Tbl WHERE UserID = ".$ViewedUser->showUser()); while ($Row = $DB_Result->Fetch()) { echo sprintf("%s ... Value \$%.2f<br />", showDescription($Row['Color'], $Row['Year'], $Row['Make'], $Row['Model']), $Row['Value']); } echo "<br /><b>Boats Owned:</b> <br />"; $DB_Result = new db_query("SELECT Size, Make, Model, Year, Color, Value FROM Boats_Tbl WHERE UserID = ".$ViewedUser->showUser()); while ($Row = $DB_Result->Fetch()) { echo sprintf("%s - %s %s %s %s ... Value \$%.2f<br />", $Row['Size'], $Row['Color'], $Row['Year'], $Row['Make'], $Row['Model'], $Row['Value']); } becomes: $DB_Result = new db_query("SELECT Type, Make, Model, Year, Color, Value FROM Asset_Tbl JOIN Type_Tbl USING TypeID WHERE UserID = ".$ViewedUser->showUser() . " ORDER BY Asset_Tbl.TypeID"); $Type = ''; while ($Row = $DB_Result->Fetch()) { if ($Type !== $Row['Type']) { $Type = $Row['Type']; echo "<h2>$Type</h2>"; } echo sprintf("%s ... Value \$%.2f<br />", showDescription($Row['Color'], $Row['Year'], $Row['Make'], $Row['Model']), $Row['Value']); } //<h2>Car</h2> //Car ... Value $ //... //<h2>Boat</h2> //Boat ... Value $ //... Your classes are also very tightly coupled to your database normally your Value Object only represents the User it does not load it from the database a DAO is responsible for that. A Value Object can be considered like the Integer class in Java it's only parent is Object, a Value Object is to represent a certain entity throughout your application. Something like: class User { private $field1, $field2, $field3, ...; //setters,getters (validation, nothing more) } And used like throughout your application. someFunction(User $u); someOtherFunction(Integer $i); If however you want to insert/update the user records from the Value Object you should consider using the ActiveRecord which places a save() function in all extending classes which inserts the user if the data is new or updates it (the fields that were changed) when the object is dirty like: $user = new User(); $user->username = 'ignace'; $user->email_address = '[email protected]'; $user->save();//INSERT User_Tbl (username, email_address) VALUES (..); $user->email_address = '[email protected]'; $user->save();//UPDATE User_Tbl SET email_address = .. WHERE UserID = ..;
  18. Are signs of poor database design.
  19. Not applicable as in nothing to do with queries or your database design structure. PHP and Java are very different as PHP only "lives" for as long as a request and how you model your application is entirely up to you. Post some code you want to shed some more light on so far you provided no example just vague descriptions.
  20. Just redirect those 8 domains to your main domain domain.com A 11.12.13.14
  21. $variable = $GLOBALS['name']; is hardly a tip as it's the same as: global $name; $variable = $name; Some prefix globals with gbl (for example $gblName) as they think it's a way around the problem while it's not like Roopurt has pointed out. function foo( $a, $b, $c ) { global $total; $total = $a * $b + $c; // Let's say $total is now: 34 magical_function(); // Does $total still equal 34? We DONT KNOW! // It's global so magical_function might have altered it without our knowing. echo $total; // Might be 34! Might be something else! } Globals are bad no matter how small the application.
  22. Have you got this setup? Server: functions.inc Client: require('http://server.com/functions.inc'); Also allow_url_include should be set to On on your Client
  23. Try out an IDE like NetBeans or Eclipse PDT these contain tools to automatically format your code against a certain naming convention (or your own for that matter). Personally, I use PhpStorm and I copy-paste any code on these forums into it and select Format where the IDE format's the entire code.
  24. That's not what I meant. I surely hoped there would be some specific document/book that discussed these advanced MySQL features/uses and I actually wanted to know the title of this document/book. Although your lmgtfy turned up some good results
  25. I think this is quite obvious http://www.work-server.com And this indeed doesn't work because your .php is parsed on the client server and the result is returned as a response so you'll have to rename it to for example .inc However I do not recommend it as anyone will be able to look up your source code.
×
×
  • 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.