Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Here is an example: <html> <head> <script type="text/javascript"> function showDiv(selectedDivNo) { var divNo = 1; while(document.getElementById('div_'+selectedDivNo)) { document.getElementById('div_'+divNo).style.display = (divNo==selectedDivNo) ? 'inline' : 'none'; divNo++ } return false; } </script> </head> <body> <a href="#" onclick="return showDiv(1);">Show div 1</a> <a href="#" onclick="return showDiv(2);">Show div 2</a> <a href="#" onclick="return showDiv(3);">Show div 3</a> <a href="#" onclick="return showDiv(4);">Show div 4</a> <a href="#" onclick="return showDiv(5);">Show div 5</a> <br /> <div id="div_1" style="display:none;">Div 1</div> <div id="div_2" style="display:none;">Div 2</div> <div id="div_3" style="display:none;">Div 3</div> <div id="div_4" style="display:none;">Div 4</div> <div id="div_5" style="display:none;">Div 5</div> </body> </html>
  2. Hmm, I'm not going to take the time to try and interpret that code - especially since you didn't bother adding line breaks or any other formatted to help interpret it. But, you can try changing (var a = 0; a <= 5; a++) To (var a = 0; a < 5; a++) And (var b = 0; b <= 4; b++) To (var b = 0; b < 6; b++)
  3. $content file_get_contents('http://www.somedomain.com/somepage.php'); preg_match_all("#<a.*?href=\"([^\"]+)\"[^>]*>Click here to find out more</a>#", $content, $matches); print_r($matches[1]);
  4. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315388.0
  5. Well, check the manual, that's what it is there for: http://php.net/manual/en/function.strtotime.php If the cutoff time is 7 days before the draw time, here is one possible solution: $drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010 if(strtotime('+7 days') > $drawTime) { //Don't allow submission } else { //Allow submission }
  6. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314962.0
  7. [Moving to MySQL forum] Is it really any more data than serializing an array of the data? In fact it would probably be less "total" data using a separate table. If you used a serialize array you have the problem which you first proposed - how big do you make the field? I don't know all the specifics, but I'm pretty sure that there is wasted space when the size of a field is much larger than most of the values that it will store. So, you would ahve to make that field big enough to store the largest array of hobbies that any one user might have, even if most users only list one or two hobbies. Plus, as I stated previously you lose all ability to use the full benefits of a database by JOINing the tables. By using a separate table you would only need a value field of around 16-20 characters - or whatver you think would be long enough to hold the longest single hobby value. But, the table layout I proposed is really only appropriate if the users can enter their hobbies in free form. If you were going to have a set list of hobbies for users to choose from you would actually want to use three tables: one for the users, one for the different available hobbies, and the third to associate users to hobbies using just the IDs of each. Then, if a user wants to list 50 hobbies you would have 50 records each with two field that only hold an ID value of only a few digits. It might seem like this is a lot more trouble than it is worth. But, once you learn how to really use databases you will understand the power that it brings.
  8. Yeah, but that is still a flawed solution. The problem is that your original array looks like this array ( 0 -> 1, 1 -> 2, 2 -> 2, 3 -> 3 ) After using array_unique() you are left with array ( 0 -> 1, 1 -> 2, 3 -> 3 ) ... because the keys are preserved. Therefor there is no element with an index of 2. You can either reset the array indexes as requinix proposed. But, there is an even easier solution - DON'T USE A FOR LOOP. All you want to do is iterate through each element in an array. So, just use foreach() - that's what it is for. $unique = array_unique($suggest); foreach($unique as $value) { echo "{$value}<br>\n"; }
  9. You shouldn't be storing arrays in a database. Instead you should be using the database how it was intended. If you have a many-to-one relationship then the data should be stored in an associated table. For example, let's say you have a record for each user in the "user" table. Then, let's assume you want to capture a list of each users favorite hobbies. You do not want to compile all the user's hobbies into an array and store the array into a "hobbies" fields in the user table. Instead you would have an associated table to store one or more hobbies for each user. Each hobby for each user would be an individual record. Example records: Users table ID | name 1 Bob 2 Dave Hobbies table userID | hobby 1 Archery 1 Reading 1 Quilting 2 Pillow biting 2 Felching From that data you can see Bob's hoobies are archery, reading and quilting. Dave's hobbies are pillow biting and felching. There is a lot more you can do with this data than if you stared it in an array. For example you could find a list of all users who have a common hobby, get totals of users by hobby, etc.
  10. LOL. I just signed up on your site using a fake email address and bypassing the confirmation code, by using sql injection. If I wanted to be really mean I'd try to use your donation page to try and submit a negative amount, but I'm not into stealing, just trying to advise on better methods.
  11. Huh? With all due respect, my commentswere to explain why what you are asking for is not feasible/advisable. As ManiacDan already stated the purpose of passing data from a form is to do so in a name/value format. Sending data that you already have available from the database will eventually lead to data inconsistencies and/or corruption. It is just a bad practice. But, it is your application, so do with it what you will. I believe (as would most seasoned developers) that it is a poor practice. Plus, since this code is for a registration page (step 4 of 6 to be exact) you are leaving the door open for a user to sign up for subscription level 10 (which should be $19.99 per month recurring) for free.
  12. <html> <head> <script type="text/javascript"> function showHideDiv(linkObj, divID) { var showDiv = (linkObj.innerHTML!='Hide div.'); document.getElementById(divID).style.display = (showDiv) ? 'block' : 'none'; linkObj.innerHTML = (showDiv) ? 'Hide div.' : 'Show div.'; return; } </script> </head> <body> <a href="#" onClick="showHideDiv(this, 'theDiv');">Show div.</a> <div id='theDiv' style='display:none;'>I'll be shown if you click it </div> </body> </html>
  13. The "price" is one of the properties of the "sub_level" in your database. You should not be passing the price as the value of the option field. You should be passing the "sub_level" as the value for the options. Then use that value of the receiving page to query the database and retrieve the correct price. By including the price in the actual submitted value you are leaving yourself open to usersmanipulating the prices since they can manipulate the submitted data.
  14. That sounds fairly simple to me. Not that it won't take time, but the logic should be simple. In addition to raw materials you also need to define specific "products" that are made up of various quantities of raw materials. I see no reason to put this logic in the code. Just create the necessary db tables to define the products and the materials and quantities needed of each. All of this can be done so anyone can create new "products". I would think that an estimate would require the estimator to enter in individual products with the option to enter additional quantities of raw material as needed. It is one "script", but that script would be used to generate multiple pages - if that is what you want. You apparently have multiple pages for each material type now. There's no reason you can't keep doing that but with one single script that uses the material ID to build the page to be specific for the materials of that type. Build it to look however you wish.
  15. You're using eval, why? var retval = eval(card + ".checkCardNumber(\"" + form.CardNumber.value + "\", " + tmpyear + ", " + tmpmonth + ");"); Just create one function that takes an additional parameter for the card type. Or if you want to keep the logic separated between functions, then jsut create one primary function that takes all the parameters plus the card type, then use a switch statement in that function to call the appropriate validation function.
  16. That's funny, because the error is this: onsubmit = "CheckCardNumber(this.form)" You need to use "return" in the onsubmit function call, like this <form onsubmit="return CheckCardNumber(this.form);" target=""> Otherwise the true/false you return from the validation function is not used. I make that mistake all the time. Although debugging is always a good idea, it probably wouldn't have helped you in this instance because at every step the code would probably have the value you expected right up to the last step of returning true/false.
  17. Yes, materials are "materials", thus they belon in the same table. You just differntiate between them based upon type. In fact, let's assume you need to add a new material type down the road. Using the current strcuture it would require a whole new table and probably a lot of additional code to support it. Whereas, if you had a materials table and a type table it is as simple as adding another type to that table (I assume you have admin features to add/edit materials). Simple, the links on that materials management page simply pass the type ID of the materials type you want to edit. The management page takes that ID, queries the DB for all the materials that apply to that type and provides the form for edit. I don't know what you have now, but I suspect you have independant pages for editing all the different material types. With this logic you just need one.
  18. Take a look at these: http://www.tuxradar.com/practicalphp/14/1/4 http://bytes.com/topic/php/answers/496432-php-function-call-vbs
  19. I'll echo mikosiko's statements. If you had properly set up your database, getting the data for a particular project: materials, quantity, price, etc. could be achived with one single query instead of running through a thousand lines of code. To build upon what mikosiko's started, here is a rough example of how I would probably approach this: Materials table: includes id, name, description, price per unit, type ID, etc. Types table: includes type id and description. (Note: if a product can belong to multiple types then you wouldn't include type id in the materials table, instead you would use a third table to make many-to-one associations) Projects table: include project id, customer id, project name, date, and other "singular" data associated with the project Project_detail table: this would include all the materials (and labor if needed) along with the quantity: project id, material id, qty Using a structure such as this, I could get all the details of a project along with pricing with a query such as this: SELECT p.project_name, p.project_date, c.client_name, m.material_name, t.type_name, m.material_price, pd.quantity, (m.material_price * pd.quantity) as sub_total FROM projects as p LEFT JOIN clients AS c ON c.client_id = p.client_id LEFT JOIN project_detail AS pd ON pd.project_id = p.project_id LEFT JOIN material AS m ON m.material_id = pd.material_id LEFT JOIN types AS t ON t.type_id = m.type_id WHERE p.project_id = 5 Um, I wholeheartedly disagree with that statement. I have seem numerous problems happen when a developer used * instead of explicitly stating the fields that they needed. Using '*' requires the database to return ALL fields in the tables being queried instead of just the data that is needed - therby conserving resources and being more efficient.
  20. As my signature states, I don't test my code, so there may be typos. I expect that once the code is dropped into the application that the person with the code can find and fix them. Anyway, I left out the ending double quote for the value inside the option tag. This line should be correct: $region_filter_options .= "<option value=\"{$row['region']}\"{$selected}>{$row['region']}</option>\n";
  21. Well, the problem is that you are doing an ASSIGNMENT in the IF condition and not a COMPARISON (i.e. a single equal sign instead of a double equal sign). But, you are making the logic in that IF statemetn way more complicated than it needs to be. You don't need to test if the value has a string length > 0 since you are already testing if it is equal to one of the available options. Also, I would advise against having to completely different lines of code for creating the options. It will only lead to problems down the road. Here is a more elegant solution. while ($row = $db->sql_fetchrow($result)) { $selected = (isset($_GET['REGION_FILTER']) AND $_GET['REGION_FILTER']==$row['region']) ? ' selected="selected"' : '' ; $region_filter_options .= "<option value=\"{$row['region']}{$selected}>{$row['region']}</option>\n"; }
  22. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=314750.0
  23. Haven't tested, but I think you could create your query something like this: $selects = array(); for($i=0; $i<$days; $i++) { $newdate = date("Ymd", strtotime("$date1 +$i days")); $selects[] = "(SELECT * FROM $newdate$var WHERE node=1)"; } $query = implode("\nUNION\n", $selects) . 'ORDER BY a LIMIT 10',
  24. Yeah, I take a little offense at the fact that because you don't understand something you seem to think it is not "proper". What is not proper was your previous logic of running queries in a loop instead of using a simple JOIN. Did you even try the code I posted? Here is the SAME query without using aliases SELECT categories.id, categories.category_name, COUNT(categories.id) as active_count FROM categories LEFT JOIN category_relations ON category_relations.member_of = categories.id AND category_relations.active = 1 GROUP BY categories.id ORDER BY category_name That's definitely mpre c;uttered and less readable than what I originally posted: SELECT c.id, c.category_name, COUNT(c.id) as active_count FROM categories as c LEFT JOIN category_relations as cr ON cr.member_of = c.id AND cr.active = 1 GROUP BY c.id ORDER BY c.category_name
  25. Look at how the headers are created in example #4: http://us.php.net/manual/en/function.mail.php
×
×
  • 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.