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. Look like I rushed the explanation a bit. After the second read-through, it looks like you want to seperate the exlanatory text from the input field, like: Fill out first name: -spacing- [input field] This is how you do it: 1. Start by getting the (X)Html right. Something like <!-- Inside a <form>-tag --> <div> <label for="a-field">Explanatory text</label> <input name="a-field" type="text" title="Description for a-field" value="" /> </div> <div> <label for="another-field">Explanatory text</label> <input name="another-field" type="text" title="Description for another-field" value="" /> </div> 2. And the css: /* Align divs */ form div { float: left; width: 100%; height: 40px; clear: both; padding: 10px; } /* Align label and inputs */ form label, form input { width: 45%; line-height: 2.5; height: 30px; display: block; float: left; clear: none; } This will allow you to style the text and input fields. Change the CSS to fit your needs.
  2. Css is how you should alter the presentation. Something like: option { padding-left: 3px; } Should give them some space.
  3. Yes, it would. I'm Norwegian myself, and it works perfectly. - Use utf8_general_ci as collation - Set PHPs MySQL(i)s charset by using mysqli_set_charset($connection, "utf8"); - Save files at UTF-8. These three steps will ensure transfered data to the database is UTF8. Else, you might experience weird charachters in the DB. This issue if often solved by utf_encode($variable), but you should not have to do this.
  4. I've thought a little about this. How about exceptions? You only need to use striplashes() if get_magic_quotes_gpc() is on. No need for the if/else there. mysqli_real_escape_string does return a string, so no need for a variable. Easy readable code is always better. $errors = array(); try { $postTitle = validate_text_input($_POST['post_title'],[font=monospace] [/font]'Please enter a title for your post.'); $postSubtitle = validate_text_input($_POST['post_subtitle'],[font=monospace] [/font]'Please enter a subtitle for the blog post.'); $postBody = validate_text_input($_POST['post_body'],'Please enter the body of the blog post.'); } catch (Exception $e) { $errors[] = $e->getMessage(); } function validate_text_input($input_name, $error) { if (empty($input_name)) { throw new Exception($error); } if (get_magic_quotes_gpc()) { $input_name = stripslashes(trim($input_name)); } return mysqli_real_escape_string($dbc, trim($input_name)); } I'm developing a lot of similar funtionality myself at the moment. This is my Integer check: /** * private boolean isInteger() * * Checks wheter input is a valid integer and a valid string version of integer. * * @param Type $number The number to check * @return boolean TRUE on confirmed integer. FALSE else */ private function isInteger($number) { return ctype_digit($number) && is_int($number); }
  5. This is not really that hard. You just have to make sure all phone numbers also have an unique identifier alongside a foreign key to the user table. Users (id, firstname, lastname, day_of_birth, etc....) phones (phone_id, user_id*, number) Email (email_id, user_id*, email) so on... To find all emails, numbers, etc, just do a query with "SELECT * FROM table WHERE user_id = $user_id". To delete/modify a number, use the etc_id like "DELETE from table WHERE some_id = $some_id LIMIT 1/UPDATE table set phone = $variable WHERE some_id = $id". The phone/email/etc id, you add to the URL of a delete/update button link to take you to update/delete.php?id=$variable. This will make sure data integrity is strong. Use auto_increment on phone_id, email_id and resident_id, and tie them to a user. Make sure phone numbers, emails and residents are unique. They should be anyway. A would recommend a Nation table and city table too if you need to make sure residents have high integrity.
  6. Use "Paste as plain text" in the editor. The Icon is located to the far right, left to the word pasting button.
  7. .blue:hover { background: url('path_to_image') 100% 100%; } That code must be in your CSS. .blue:hover is an ACTION, not a different class. You dont use class="blue:hover" in your markup. Another trick is to fit two images into one. Lets say your rows are 30px in height. Use an image of 60px in height, and add the hover-image beneath your standard image. The trick is to change background-position on hover: .blue { background: url('path_to_image') top left repeat-x; } .blue:hover { background-position: bottom left; } This article describes the trick, even though the hover image is the top one here.
  8. With IE8/9, most problems should really be gone. The issue now is more related to eye-candy than to the actual layout. My tip is to develop the grid/layout first, then specify eye-candy later on. I've almost stopped testing my web pages in different browsers. I only do that at the end of development. Regarding IE6/7 **** that ****. Help the internett to get rid of those browsers by not supporting them. I've acctually blocked my website for IE6 as I just hate the d**n thing. This is getting a bit emotional, but I came from a webdesign and xhtml, css background before I learned PHP. I've struggled with IE6/7 for to many hours not to hate it...
  9. Have you checked out Facebook-login or something similar? Using Dark Prince's suggestion with this should be possible. IP-adresses do change, even if that's not such a big problem as with cookies.
  10. Might possibly be a String-related problem. Try to typecast it to int. (int) $quantity_stock Don't really know if this is your error, but if it returns 14, I agree with you that is weird. Wish PHP can make optional types... Would be great to be able to use Strings, Integers, Doubles, DateTimes, MySQLI or other classes as types! Crossing fingers.
  11. Do this with CSS instead. .your_div { background-color: white; // Standard color } .your_div:nth-child(even) { background-color: gray; // alternate color } Then, you don't need any alterations in the while-loop.
  12. I really like what google has done with Youtube. The front page looks a bit weird, but the functionally and overall interface is just so nice and intuitive.
  13. I don't mind, Larry. I asked for the social forum, so I tried to start a thread. Guess people are here to learn and discuss code, not to talk politics or sports.
  14. Try this instead for $q: $q = 'INSERT INTO council_terms VALUES (NULL, '.$_POST['council_term_start'].', '.$_POST['council_term_end'].', '.$_POST['council_term_voters'].', '.$_POST['council_term_chiefvotes'].', '.$_POST['council_term_councilvotes'].')'; I'm not sure, but I'm guessing the backslashes and the characters " and ' could be causing this. You should even escape this before using the $_POST-globsl in your SQL: $term_start = mysql_real_escape_string($dbc, $_POST['council_term_start']); $q = 'INSERT INTO council_terms VALUES (NULL, '.$term_start'.... And so on.
  15. timveer: Don't do the same mistake I did. Objects are not something "better", cooler or faster. You can easily combine the two, and you really should. Small scrips is often better to develop procedural. The real advantages of OOP comes into play when you need to create applications and larger systems. It would be good practice to switch MySQLI from procedural to OOP. It will allow you to understand more without re-inventing everything in OOP. As Larry said, just use your connection as a parameter in each function. You are already doing good by separating logic from presentation in your functions. And please not this: Try using this a username: ' '; SELECT * FROM SOME_TABLE . Your functions are vulnerable to SQL Injection. Use Mysqli_real_escape_string() to prevent it. ; )
  16. Yes, it is timveer. In Object-oriented code, you would like to pass a Mysqli object to a function rather than just the connection. This is an example from my NationController controller class that handles nations. <?php include('model/Nation.php'); class NationController { private $mysqli = null; // MySQLi-object /** * Public constructor for NationController * * @param Mysqli $mysqli - A MySQLi-connection object. See DBController */ public function __construct(Mysqli $mysqli) { if ($this->mysqli == null) { $this->mysqli = $mysqli; } } /** * Creates nation objects in model/Nation.php. * * Use static function Nation::getNations to return * the array holding the nations. The other functions * add nations to this array. * */ public function getAll() { if ($result = $this->mysqli->query('SELECT * FROM abc_nations')) { while ( $row = $result->fetch_row() ) { new Nation($row[0], $row[1], $row[2]); } } } /** * Get nation by ID. * * @param int $id - An identity number for a nation * @throws Exception - InvalidArgument $id (integer) */ public function getNationById($id) { if (!ctype_digit($id) && !is_int($id)) throw new Exception('- ID must be an integer'); if ($result = $this->mysqli->query('SELECT * FROM abc_nations WHERE id = '.$id.' LIMIT 1')) { while ( $row = $result->fetch_row() ) { new Nation($row[0], $row[1], $row[2]); } } } /** * Get Nation by Iso code * * @param String $iso - The unique ISO number for a country */ public function getNationByIso($iso) { $iso = $this->mysqli->real_escape_string($iso); if ($result = $this->mysqli->query('SELECT * FROM abc_nations WHERE iso like "'.strtoupper($iso).'" LIMIT 1')) { while ( $row = $result->fetch_row() ) { new Nation($row[0], $row[1], $row[2]); } } } /** * Get nation by name * * @param String $name - The name of the country */ public function getNationByName($name) { $name = $this->mysqli->real_escape_string($name); if ($result = $this->mysqli->query('SELECT * FROM abc_nations WHERE name like "%'.$name.'%" LIMIT 1')) { while ( $row = $result->fetch_row() ) { new Nation($row[0], $row[1], $row[2]); } } } }
  17. I've also struggled with this krashchiy, and I'm guessing it has to do with the php-configuration. Do you know about this, Larry? Locale is not affected in my hosting inviorment, but I get it working when developing in localhost on Xampp.
  18. Use Netbeans or Eclipse. Both free and with syntax highlighting, automatic code completion, error hinting and other important stuff. I would not recommend notepad++ if you are not and experienced PHP developer. The reason is because you lose some great functionality. When developing classes in PHP, hinting of object variables and methods are a real time-saver. It's easy to overlook $this->, self:: or parent:: in a class, and Notepad++ will not tell you when you do. Netbeans and Eclipse is also available for Java/.net and other languages with built in database-handling, compilation and such. It's good to get it all in one program. As to Jonathon's suggetions, I haven't heard about them. As Eclipse/Netbeans are available for both PC and Mac, that's an important thing for me personally.
  19. Good luck. Just ask if you're wondering about anything. It's not that easy to grasp in a heart beat. I've helped a lot of people with similar problems. (Sub-menues, and all other kinds of three-structures do really share the same solution.) You can think of this like a multi-dimensional array if that helps you out. Larry writes about this in PHP 5 Advanced (I think) where he builds a PHP and database system for a todo-list. That is really pretty much the same as you do here. Hope that helps.
  20. Hey Note: This query is actually returning the right/correct data. You may skip the initial explanation... I'm currently working on a large query with a lot of subqueries. What I need to do, is to count the total number of games won, defeated and undecided. (by example, a 1-1 score). The count should be based on a specific team and also differ between home and away matches. This is the structure of the result from the query: Team / home_wins / home_defeats / home_undecided / away_wins / away_defeats / away_undecided What I'm wondering: The problem is that subqueries cannot return more than ONE result. Because of this, the calculations needs to be performed on a per-league-bases. Because I'll still need similar functionality next season, I'm wondering if I could make a function/use a changable variable here. It should be possible to change the league_id for this calculation every year, or even better, find a way to calculate each league of it's own. I just don't think that's possible. Here's the query: SET @league_id = 11; SET @club_id = 11; SELECT games.league_id AS league_id, league.name AS league, ( SELECT SUM(goals_club1 > goals_club2) FROM cnk_soccer_games WHERE club1_id = @club_id AND league_id = @league_id ) AS home_wins, ( SELECT SUM(goals_club1 = goals_club2) FROM cnk_soccer_games WHERE club1_id = @club_id AND league_id = @league_id ) AS home_undecided, ( SELECT SUM(goals_club1 < goals_club2) FROM cnk_soccer_games WHERE club1_id = @club_id AND league_id = @league_id ) AS home_lost, ( SELECT SUM(goals_club1 < goals_club2) FROM cnk_soccer_games WHERE club2_id = @club_id AND league_id = @league_id ) AS away_wins, ( SELECT SUM(goals_club1 = goals_club2) FROM cnk_soccer_games WHERE club2_id = @club_id AND league_id = @league_id ) AS away_undecided, ( SELECT SUM(goals_club1 > goals_club2) FROM cnk_soccer_games WHERE club2_id = @club_id AND league_id = @league_id ) AS away_lost FROM cnk_soccer_games AS games INNER JOIN cnk_soccer_league AS league ON ( games.league_id = league.id ) WHERE ( games.goals_club1 IS NOT NULL OR games.goals_club2 IS NOT NULL ) AND league_id = @league_id GROUP BY games.league_id An explanation of the query: - The query is only counting games from league_id 11 - Only counting games where the score is not NULL (the games are already played) - The results are grouped on a per-league-basis - Each subquery checks the score of club1 to that of club2 (home and away team) - The result of the sub-queries depends on the comparisons (should the home/away team win?).... And to wheater OUR team is the home or away team Hope someone can help me with this.
  21. From what I'm reading, I would suggest two tables for this. First of, I would start with the basic "user" table. That is what you call parent. In my example, id is the important thing. It should be primary key and auto_increment. This is what's identifying all the unique bloggers bloggers (blogger_id, other_blogger_colums) We then make the blog table. Again, the_blog_id is identifing each unique blog. Each unique blog then have an unique blogger associated with it. blogs (the_blog_id, blogger_id*, other_blog_columns) ... And a blog_post. Every blog post has an unique identifier in blog_post_id, and what is called a foreign key, a unique identifier in another table, to identify what blog and what blogger the post belongs to. blog_posts (blog_post_id, is_post_of_this_blog_id*, belongs_to_this_blogger*, other_blog_post_columns) At last we make a table where we add bloggers that are allowed to whatch another blogger's personal blog. It works this way: You identify a unique blog by it's ID. You then add an ID of a blogger that is allowed to read a blog. allowed_to_read(the_blog_id, bloggers_allowed_to_read_id) Underlined: primary keys Asterix (*) : foreign keys ------------------------------------------ Some test data to make this less abstract: First assume we have three bloggers with an ID, a firstname and a lastname. bloggers (1, "Bobby", "Miles") bloggers (2, "Johnny", "Cash") bloggers (3, "John", "Sailor") We then have two blogs (with blog ID, blogger_id and title for the blog) Both belongs to Bobby Miles blogs (1, 1, "This is Bobby Miles' personal blog") blogs (2, 1, "This is Bobby Miles' second personal blog") We then create three blog posts with a blog_post_id, a blog_id, a blogger_id and the actuall blog_content blog_posts (1, 2, 1, "First blogpost in Bobby Miles' second blog. Just want to say hi to whoever can read this!!!") blog_posts (2, 1, 1, "First blogpost in Bobby Miles' first blog! Just want to say hi to whoever can read this!!!") blog_posts (3, 2, 1, "Second blogpost in Bobby Miles' second blog! Just want to say hi to whoever can read this!!!") We then add other bloggers who can read Bobby Miles' two blogs. Now user_id 2 (Johnny Cash) & 3 (John Sailor are allowed to read the FIRST blog (id 1) of Bobby Miles. None of them, are however, allowed to read the SECOND blog if the checks are performed correctly in the php script. allowed_to_read(1, 2) allowed_to_read(1, 3) ------------------------------------------ Do you need more help with this, or are you able to figure out the query to check if the user's allowed to read? Just shout out if you're struggling with anything. I'm a bit bussy at the moment, but there's a lot of knowledgeable people here.
×
×
  • Create New...