Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. I would say that a variable size board is good for learning. Regardless of the board size you have to go through rows, columns and two diagonals.
  2. Most likely there's no way to do that without writing a lot of code to merge the three applications together. OpenAuth might be a good solution if you can find a plugin for it on each of the applications. It's a protocol that allows a user to log into many different places at once.
  3. Ingolme

    connecting to msqli

    You can generalize a query. I've used the following algorithm in some of my projects, but you have to guarantee that the data coming in corresponds to fields in the table otherwise it will give an SQL error. Here's the MySQLi version ( I don't use MySQLi, so the piece that binds parameters could probably be improved) $query_data = array( 'first_name' => 'John', 'last_name' => 'Smith', 'age' => 40, // ... 50 other fields 'favorite_color' => 'Blue' ); // Break into fields and values $fields = array_keys($query_data); $values = array_values($query_data); // Generate placeholders $placeholders = array_fill(0, count($fields), '?'); // Sanitize field names foreach($fields as &$field) { $field = str_replace('`', '', $field); } // Construct query $sql = "INSERT INTO my_table ("; $sql .= '`' . implode('`,`', $fields) . '`'; $sql .= ') VALUES ('; $sql .= implode(',', $placeholders); $sql .= ')'; $stmt = $mysqli->prepare($sql); // Bind parameters // In PDO this wouldn't be necessary since you can pass an array when executing a query // MySQLi required parameters to be bound with bind_param // I strongly recommend PDO over MySQLi $types = ''; foreach($values as $index => $value) { // The first character of integer, double and string matches what MySQLi expects $type = gettype($value); $types .= $type[0]; } array_unshift($values, $types); call_user_func_array(array($stmt, 'bind_param'), $values); // Execute the statement $stmt->execute(); I work in PDO, which is safer for this type of operation because you don't need to specify the type of the parameters. Here's the PDO version: $query_data = array( 'first_name' => 'John', 'last_name' => 'Smith', 'age' => 40, // ... 50 other fields 'favorite_color' => 'Blue' ); // Break into fields and values $fields = array_keys($query_data); $values = array_values($query_data); // Generate placeholders $placeholders = array_fill(0, count($fields), '?'); // Sanitize field names foreach($fields as &$field) { $field = str_replace('`', '', $field); } // Construct query $sql = "INSERT INTO my_table ("; $sql .= '`' . implode('`,`', $fields) . '`'; $sql .= ') VALUES ('; $sql .= implode(',', $placeholders); $sql .= ')'; $query = $pdo->prepare($sql); // Execute the query $query->execute();
  4. If you're showing the result in a table, the quickest solution is to use an existing plugin to allow for table sorting. https://www.google.ca/search?q=jquery+sort+table If it's not a table, or you don't want to rely on a bulky library, then you can store your data in a Javascript data structure and sort the data structure, generating HTML upon sorting.
  5. You could copy the contents into a new file, delete the old one and then rename the new file. There are some details you might want to take into account which are mentioned here: http://php.net/manual/en/function.touch.php#56399
  6. Yes, any string will work, literal or not.
  7. You can add some CSS to display links inside the menu as inline. W3.CSS has it set to block by default since most people just want a list of links.
  8. Aptana is a development environment. drupal's a content management system. They're not related. If you want to run PHP code you need to install a web server on your computer and access pages from the browser. If you want something easy, try a regular content management system, like Wordpress. My experience with drupal is that it's unnecessarily messy and complicated. The problem is that if you want complete control over how your website looks and behaves you're going to need technical skills. The easier the tool is to use, the less control you have over what it does.
  9. All you're doing is giving it a string. If you want to load content from other files you should read the AJAX tutorial. It's more complicated than just assigning a string.
  10. If you can guarantee that there are no spaces or line breaks before the opening <?php tag then it's probably because your document is encoded as UTF-8 with a byte order mark. To solve that, open your document in a code editor and save it with a UTF-8 encoding that doesn't have a BOM.
  11. Coding for emails is very different than coding for a website. You have to use old attributes and inline CSS to get it to render properly in email clients.
  12. When you cast a value as INT, it stops at a space because spaces aren't parseable as numbers. Why is there a space? You'll have to do some string operations to remove the space before casting to INT.
  13. You probably can cast it in the SELECT part, then order it. Something like this: SELECT t.*, CAST(column AS INT) AS sort_field FROM table AS t ORDER BY sort_field
  14. Aside from Javascript 6, none of these things are even remotely related to the creation of websites.
  15. Generally, modal windows work a little differently than other page layout content since they always have to be in view regardless of how far down the page the user has scrolled.
  16. It might be an issue with how the elements are nested. It looks like you're using Javascript to arrange the boxes. Did you write the Javascript?
  17. Your question is not clear. Which value are you referring to, and what are you changing? What does "change to random" mean?
  18. There's nothing we can do here to help you. Location data is only available when the user uses an application and grants permission to it.
  19. You can't find out the location of any phone knowing just its number, that would be a severe privacy violation. You could build an app that sends location data to you and try to convince the user to install it on their phone.
  20. You can have multiple recipients separated by commas. $recipient = 'user1@somedomain.com, user2@somedomain.com'; If you want to use the Cc and Bcc fields you can add them to the additional headers: $email_headers = "From: $name <$email>\r\n"; $email_headers .= "Cc: user2@somedomain.com";
  21. XSL is a styling language, its capabilities of actually modifying data are very limited. You might want to look into a programming solution with a server-side programming language, or Javascript if you're on the client side.
  22. Unfortunately, this has the same issue as the rest of the CSS frameworks: Mixing content with presentation. In addition to that, it can be replaced by the style attribute, which is more customizable because you can choose the values; <h1 class="main-title" style="padding:20px; margin: 40px; color: #F00; background-color: #000; text-shadow: 2px 0 #000">Big title</h1> <button class="primary-btn" style="padding: 0 20px; border-radius: 5px; box-shadow: 4px 0 #000">click</button> I can't comment further because the documentation is very short.
  23. A timestamp will give you a unique value unless two users appear at the same second. Get the timestamp by using PHP's time() function. If one second is not precise enough, there's microtime() the gets microsecond precision, pretty much guaranteed to give two users a different value even if they visit the site at the same instant.
  24. Oh, right. You cannot print anything at all before setting a cookie. Cookies get sent with the HTTP headers, and once something is printed headers are no longer allowed to be sent.
×
×
  • Create New...