Jump to content
Larry Ullman's Book Forums

Antonio Conte

Members
  • Posts

    1084
  • Joined

  • Last visited

  • Days Won

    126

Everything posted by Antonio Conte

  1. 1. Strings can be used with array syntax. Feel free to use substring though. 2. Concatinate strings into one large query string. 3. Give me one day. Developing a class for you now. Glad you learn something from this.
  2. Short answer now. Maybe i'll update later. I would just create an associative array with what you need then run several queries to fetch the data. All this data is bases on WHERE clauses where you query one user Id. $user = array( "id" => $ id, "bla" => $bla, "jobs" => $jobs-array, // query two "images" => $image-array, ); Once this works, feel free to improve upon it but making sure it works is the most important thing. Don't get hang up in getting it perfect the first time around. Writing on phone btw. Sorry for the short code example.
  3. You are of course both right. I know this has been handled sloppy from the start. Giving these details over the phone seems like the best idea yet. I have now talked to the host. I need a dedicated IP-adress and a SSL certificate. It was not as expensive as first thought, so I will definitely invest in that. Besides SSL, what kind of precaution should i take? What kind of encryption precautions should I take? I ask since this is a vital part of ecommerence too, and I've never dared to play with something like that before. What can I safely store in a database? What should not be stored there? Thank you for being critical, people. I know I haven't worked hard enough to secure our members.
  4. Yes, that's what's happening. As Jonathon says, the code below will do the same. Ternary is a shorthand if/else. $color = '#eeeeee'; // Set the initial background color. while ( $row = mysqli_fetch_array($r, MYSQLI_ASSOC) ) { if ( $bg == '#eeeeee' ) { $bg = '#ffffff'; } else { $bg = '#eeeeee'; } } For just the background colors, bahaa has a point. This can very well be done in CSS. That's what I use to do.
  5. It works because of this: Before anything: $bg = '#eeeeee'; 1. Iteration: ($bg=='#eeeeee') is now TRUE and '#ffffff' is assigned to $bg. 2. Iteration: ($bg == '#eeeeee') is now FALSE because #ffffff was assigned last time. #eeeeee is therefor assigned to $bg 3. Iteration: ($bg=='#eeeeee') is now TRUE and '#ffffff' is assigned to $bg. This is done until the all rows are fetched from MYSQL and the result is alternating colors. The important part to understand: Right hand side operations gets executed first. The result is then transfered to the left hand side. This is why something like this works: $left = $right = false; // Both are false
  6. It's not harsh. This is very personal data that should not get in the wrong hands. The problem is that the supporter organization we are part of requires this information for issuing out tickets for football matches. We must hold these data even if I don't like this. So far I've stored this data on my encrypted and passport protected personal computer. That is really the most secure we can do at the moment. Gmail offers SSL, so we recommend our users to transmit passport numbers and social number there. We don't offer any online forms for this. This is exactly why I'm asking what kind of measures I need to take to be sure my members are protected. Will send an email to my host and ask what they can do for me.
  7. Hello, everyone. I run a website where we are required to get personal information such as passport numbers, social numbers, birthday/place and other personal information. I don't want these kind of data to get lost, so I've required them sent over mail instead. (Hopefully they have SSL. Gmail have) I would like to build a website form instead. What precautions do I need to take for this? My host offers SSL certificates, but that may be too expensive for us. We are a small non-profit organization. Any suggestions here? Is SSL a requirement or could I possibly solve this another way? Thanks in advance. Never done something like this before.
  8. Had some more time today. Usernames are unique as an equal one will just overwrite the old one. This script should therefor not be used twice or you must write a check somewhere to ensure that old users are not overwritten. There is improvement to be done here, but this should be a good start. Added a small key check. Will work if you add old username keys to the users array before generating any more usernames and passwords. Something to get you started: <?php // Set some variables $number_of_users = 100; $min_username_length = 3; $max_username_length = 12; $min_password_length = 8; $max_password_length = 12; // Create user array $users = array(); // Create usernames for ( $i = 0; $i < $number_of_users; $i++ ) { // find random length $namelength = mt_rand($min_username_length, $max_username_length); $passlength = mt_rand($min_password_length, $max_password_length); // Get username $username = random($namelength); // Make sure username is unique if ( array_key_exists( $username, $users ) == false ) { // Add to array $users[$username] = crypt(random($passlength)); } } // Print usernames to screen foreach ( $users as $user => $pass ) { echo 'Username: '. $user. ' Password: '. $pass . '<br />'; } function random( $length ) { // Set allowed chars $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // Create username $username = ""; for ( $i = 0; $i < $length; $i++ ) { $username .= $chars[mt_rand(0, strlen($chars))]; } return $username; } ?> The check is untested, but pretty sure there's no error there.
  9. What is randomness? Can usernames be random letters, numbers and characters or should they at least resemble real words? Such things are important to know. A way to do this is to specify a number Range use rand() to get a number then chr() to get a character. $min = 30; $max = 70; $userlength = rand(3, 10); $username = ''; for ($i=0; $i<$userlength; $i++) { $username .= chr(rand($min, $max)); } Another is to create and fill an array with allowed characters for a username then to randomly select an item between 0 and array length. The same can be done for passwords. Sorry. Writing on phone, so it's tricky to create something good for you. That above would give you the basic idea. You might get some weird chars though. Find a range in ASCII table or use the array solution. Try a google search for username Generator php or something. This probably exist.
  10. To be honest, I'm not sure. Just based on experience, I feel there's an easier way. I might be wrong there, though. It's tricky to code a coupon system inside your own head. If you don't wanna post any code only for whatever reason, feel free to PM me some.
  11. Try changing to: You need to define what inside the $row array you want to use. Right now, you're assigning the whole array.
  12. This is what I'm not buying. Look at the abstract factory or the builder pattern to create the basic functionality. This abstract/builder class should handle promotion names, original price, shipping, handle calculations for percentage/amounts and handle expiration dates etc. With all this functionality in one single class, use polymorphism if things need to change. You should be able to create small classes for those special cases instead. Looking forward to it if you want to show us some code.
  13. You know best. I have complete confidence in that.
  14. I know that. The point was finding something comparable in PHP. After a form submission, the super global post array is pretty similar to when an event fires in other languages. When I learned about events and listeners, I'd just wished someone gave me such examples. They are often easier to understand then technical explanations, exactly what makes you my favorite writer for this stuff. You actually often do what I did her in your books, though with explanations. Something along: Hint: The post array are not really an event, they just work similar. If you are interested in the small details, search the web. That being said... Might be a stupid example, but I try. haha.
  15. Very good. You have obviously put some thought into this. I'm not buying that you should have different classes for percentage, amounts and free-shipping. You should be able to use both percentage and amount discounts on ANY discount object, and you should be able to display the discount in percent when specifying amounts and vica-verca. Free-shipping should only be a basic boolean member in the super class. I would've worked out a criteria system instead. This way, the discount class will be simple. You can just add a general discount for everyone, or you can narrow down the eligibility to those weird criterias. I tried to illustrate it in application code, but it's a bit tricky to code for others. If you like the idea, I'll surely help you out. The basic idea is to let the Discount object handle all info regarding the discount itself, including calculating new price after discount and the discount percentage compared to the original price. The object should verify that the coupon is valid regarding time/dates, but THEN ask the criteria object whether or not a specific criteria is met. This way, you delegate the special criterias out of the discount class, and your code is easier to build on and understand. If the system works, please feel free to ignore my post. I only find your problem interesting and challenging. I'm not really sure my solution is better, but I think it would be. Feel free to consider this yourself.
  16. Looks like a pretty perfect setup if you ask me. So far. When it comes to you static factories, would've skipped that. Create one solid discount class and extend that if needed. There's really no difference between a percentage and a dollar discount. It should be able to display both of those without a problem. What If you need a percentage discount, but still want to provide free shipping? Don't make things to hard to work with. With a factory, unless it's an abstract factory, you don't have that possibility. (Easily) Keep it simple. As you won't offer that many types of discounts, a factory seems like over complicating things a lot. Basic polymorphism or an interface would be recommendations here. "Super-special Valentines day 15% women's discount for men's clothes, with free shipping", here I come. Excuse my English, btw.
  17. You need to understand that events fire automatically when a certain criteria is met (or in short intervals). A onMouseoverEvent will fire on mouseovers. What you do is listen after events. The automatic listener will catch the events. That is what Jon's code does. He asks the document object (the html page) to get him all link elements (<a href="...") with this line of code: var aLinks = document.getElementsByTagName('a'); The var aLinks is now holding ALL link elements on the Html page. The events/listening is not important yet. This is when he creates listeners for (var i = 0, aLinksLen = aLinks.length; i < aLinksLen; i += 1) { aLinks[i].onmouseover = putTextInInputBox; } It's pretty much the same as doing: aLinks[0].onmouseover = putTextInInputBox; aLinks[1].onmouseover = putTextInInputBox; aLinks[2].onmouseover = putTextInInputBox; This code says: "For every a element in the HTML page, create a listener for onmouseover events. When we hear that event, run the function. The great think is that each link automatically know when a mouseover event happens. When it's hovered, it will hear that event and run putTextInInputBox. The VALUE of that link will then be added to the input box. Read up on how events work and how you capture them. It's VERY important for understanding how to write good code.
  18. Programming is what it is, you know. Once you understand the inner workings of references, values, objects, events, conditionals, loops and the likes, it pretty much boils down to syntax, names and those few special things you just gotta figure out about each language. Luckily, most of the stuff so far is really familiar. Just hoping it will continue on like that, but I'm sure it won't. The more you learn to know, the more you find out you don't know.
  19. I got this books some days ago. Huge thanks for Larry who gave it to me for free. Hope I get to the level where I can answer questions pretty soon so I can pay back. We'll see. In the meantime, expect some hopeless questions from me! Great read so far. I'm at around page 40, and I find a lot of the intro info useful. Could be shorter, but it's a beginners book. As Larry is such a great learner, and I'm familiar with events, objects and dot-syntax, I hope to pick up the language in a couple of weeks. The only problem I have is with the layout. As I read some of it on the IPhone, the switching of text placement is a bit annoying. I can even specify odd/even page layouts, so I'd liked those to be consistent at least. Big problem, right? Haha.
  20. The event part is very important. As in every language that has them, events will fire at particular times. You create a listener to catch them. It's the $_POST array in PHP, actionEvents in Java and something other in Javascript. Those details are very important to pick up, because having a solid understatement of things like that is what makes you a good programmer in the end. The devil lies in the details, isn't that the english expression? I'm only at about page 45 myself, so I'm a real newbie at JS. Hope I can pick up most of this language in a couple of weeks.
  21. I will look more into this tomorrow, but have you thought about using some JSON? Get the badges into an array and match the array key (badge id) to it with your query. You could then build this array again if you make updates to the badge table. As for scalability, this would be pretty efficient as you won't need time for disk access (SQL disk lookups) and have a constant time operation when matching with the array. (Just make sure it's an associative one) Need more help, scream out. Too tired to really look into this now. Out.
  22. Ok. Then you have ranking. Very good. Try using a function like MAX(badge_id) in the SELECT part of your query. This solved a very similar problem I had some time ago.
  23. This is a fairly common problem. It often occurs because you are outputting ANYTHING before the session_start(). It could also be any whitespace above the sesson_start() or any html/includes etc. Make sure session_start() is placed ABOVE all other PHP code and html other than the start tag (<?php) and any type of comments. (// comment, /* comment */)
  24. How do you do the internal ranking of badges? It looks like it's missing. I would've added a column like badge_rating inside the badge table. With a badge rating, you could do a SELECT bla FROM bla WHERE user_id = $id ORDER BY badges_user.date, badges.rating With a couple of joins, you have it. Edit: Ok, you only wanted ONE badge. Hmm. Look up nested SELECT queries. I'm pretty sure you need one of those to be able to find the highest rated badge in each category.
  25. Yes you can. Take my previous code. You may assign the error message to an assosiative array like so: $error_array = array(); $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; // check firstname If ( strlen($firstname) < 2 ) { $error_array['firstname'] = "Firstname must be at least 2 characters long"; } // Check lastname If ( strlen($lastname) < 3 ) { $error_array['lastname'] = "Lastname must be at least 3 characters long"; } // We are now in the html form <input name="firstname" type="text" /> <p class="error"><?php if ( isset($error_array['firstname']) ) echo $error_array['firstname']; ?></p> <input name="lastname" type="text" /> <p class="error"><?php if ( isset($error_array['lastname']) ) echo $error_array['lastname']; ?></p>
×
×
  • Create New...