Jump to content

cpd

Members
  • Posts

    883
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by cpd

  1. .length is of type Number. I'm not sure which method is called by default when using .length but either way the affect will be negligible so either method would suffice. That said I would define n outside the loop for clarity and readability purposes.
  2. No the DBMS will take care of the indexing period.
  3. Your current method treats the elements property of the form object as an object with a property of value form = { element: { value: "Somethnig" } }. When in fact its along the lines of form = { elements : array( 0 => Button, 1 => Text, 2 => Checkbox ) } There are further technicalities that going into detail will serve no purpose as you wont understand. So you need to cycle through the array: for(i = 0; i <= document.forms["Myform"].elements.length; i++) { // Code omitted }
  4. "elements" is an array not an object. You need to cycle through it and store each value in an array then return the array. The "formValue;" just before the closing script tag is not required.
  5. Assuming your database is normalised: Use the primary key of your answers table to update the relevant row. Setup your HTML so it is parsed into an array when posted to the http server. Correct the in-line if statement such that its inside the input tag so it can be checked if they previously checked it. return "<input type=\"checkbox\" name=\"question[" . $primaryKey . "]\" " . ($answer == 1 ? "checked=\"checked\"" : "") . " /> " . $question; You can access the field by doing: foreach($_POST['question'] as $primaryKey => $value) { // Code omitted } You need to update all the IDs passed as POST data with 1, then update every other record relating to said user with a 0 - this could all be combined in a single query. One final point: in your DOM there should be no single tag with the same ID as another tag hence why I removed the ID from the input tag.
  6. You can implement a select statement as described by Muddy and then use AJAX to add new entries - this would in turn update your select with a new option.
  7. Assuming the name of your form is "Myform" the above code should technically work. Can you post your entire form and the Javascript your attempting to use. Edit: Just thought you can try document.forms["MyForm"].elements...
  8. Your query has failed and returned false therefore you're passing false to mysql_fetch_array resulting in your error. If you'd read Jessica's post I'm 100% you'd of understood as it explains it clearly, I clarified what was going on by looking at the return values for http://php.net/mysql_query/ - an amazing resource to assist in debugging . People ask you to read other posts so they don't have to re-write the same god damn simple tasks over and over again.
  9. You don't need to define every possible link e.g. $route['products/view/(:any)'] = 'products/view/$1'; Provided there is a controller called Products and a method called view it will get executed as this is the default routing method - which can be reconfigured if you wish - and any arguments will be passed as parameters. Secondly, when defining routes it'll take the last defined route and overwrite any conflicting routes. In your case you have: $route['products/search/(:any)'] = 'products/search/$1'; $route['products/(:any)'] = 'products/index/$1'; CodeIgniter sees the second one and re-routes anything with "products" in to products/index/$1 i.e. every single method you've defined will now be redirected to your index method Taking into account my previous comments, remove both. Edit: Apologies for all the edits, spotted a load of grammar and language errors.
  10. I highly doubt anybody is going to search your passive code pastes when you've not even attempted to narrow down lines of code it could be in - you've only said "it doesn't work" which is obvious else you wouldn't be here in the first place.
  11. Don't just mysql_real_escape_string as its not proper protection. You can do a number of things: Validation Sanitation Type casting Prepared statements (highly recommended) Now Google your heart out to find out what each is. I can't see why your query shouldn't work. What's the contents of the session variable?
  12. Take note of the american date format. You can chain the add and subject as shown below just be careful it doesn't return false; that said if it does return false in this situation I'd argue its a programming error and you should sort it out so chaining is fine. $dtObj->add(new DateInterval('P1Y'))->sub(new DateInterval('P1D'));
  13. CREATE INDEX my_column_idx ON table(my_column) That'll index the column you specify and should make your query run faster. Normally you would index columns used in your WHERE clause as these are the conditions it has to search.
  14. You can redirect from there using the header("Location: ...") function but without seeing the rest of the script no-one can tell you if its a good idea or not as additional logic may be carried out after that if statement.
  15. Unless you've configured your http server to regonise .inc files it won't interpret it as a PHP page. You currently have include "donation.inc";.
  16. Its a method of doing it. Best/worst methods are argued from person to person as opinion varies. Just remember there's usually many ways to carry out individual tasks all of which are just as good as the next.
  17. That'll only redirect for requests that have a path starting with update. This could imply you're going to define every possible URL you have and redirect it? Why not redirect the whole thing and have PHP determine what content to serve up. <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L] </IfModule>
  18. Most mod_rewrite applications just redirect to a single page which interprets the URL. There's usually a format such as http://website.com/module/controller/action/arg1/arg2/ but it varies from app to app. The application works out the correct content to show and the MVC architecture apps usually use a Router class. Why is this relevant to you? Because I think, you think all the leg work is done in htaccess when in reality its not. More permanent things could be done in htaccess such as a 301 redirect.
  19. You would need to use AJAX to retrieve the value and then call something along the lines of document.getElementById(ID of element to change).value = dataReturnedByXHR
  20. MySQL is being thrown out the window, window locked and key melted so I strongly suggest you switch to MySQLi or PDO as per the php website . You really need to break your code down and write English comments as many people will discard your post the minute they see a massive chunk of code. The Database::query method appears to return a resource ID so you can call a mysql_fetch_assoc/array() function to retrieve the next row in the result set - of course you're going to change to MySQLi though and use mysqli_fetch_assoc()
  21. As Christian touched on you'd need people to register and use a unique identifier. Its one reason why the likes of Facebook, Twitter and many more require developers to register before interacting with their APIs - far stricter and they can keep tabs on things.
  22. It doesn't do everything at once, the parser reads it line by line. When it finds a matching case it begins to execute the code thereafter until it reaches a break statement. A fall-through, as Christian mentioned, is when another case is found before a break is found and the code in this new case is then executed; you can have as many or as few as you like.
×
×
  • 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.