Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
This is incorrect format for the sort() function sort($dirArray, $date2 SORT_ASC); sort($dirArray $date2, SORT_ASC); The sort() function takes only 2 arguments: 1 The array and optionally 2 the sort flag. And which array are you trying to sort? In your first post you talked about the variables $adate and $date2 (one dimensional arrays). But in your example in the last post you are trying to sort $dirArray which is a multi-dimensional array. The sort() method you would use will be different based upon the type of array you are using. for single dimensional arrays sort() would be the proper choice. For multi-dimensional arrays there are different methods based upon the array structure. For what you have I think you will want to use array_multisort(). Look at the instructions for sorting database results in the manual: http://us2.php.net/manual/en/function.array-multisort.php
-
If you have the dates in the format dmy there are two problems. First you need to be using leading zeros for month and day as needed (i.e. ddmmyyyy). Also, that will not sort in chronological order. You need to use the format yyyymmdd.
-
Did you see my last sentence? In this case, a web site for a Pizza Chain is only a marketing piece and in my opinioin there should be no reason that JS should be a requirement. But, you assertion that possibly restricting 5%-7% of users would translate into 5%-7% of lost sales has no basis (how many sales originate through the site, either directly or indirectly? What is the ratio of visitors to the site vs. orders?, etc., etc.). There are many factors that would influence the actual "costs" of lost sales. In any event, I agree that it would be a poor decision for any type of marketing site. But, I still maintain that there are some instances where requiring JS is valid. Particularly with "application" sites that require vast amounts of real-time functionality. In these situations the provider is sellign the use of the site as software to the end user. Requireing JS is no different than having minimum system requirements printed on the side of the box for a retail software application. In a previous company I worked for we provided a desktop publishing application via the web for the commercial printing industry. I won't say it would have been impossible to do it w/o JS, but the additional work it would have put on the user would made it an un-marketable product.
-
In my opinion that is a business decision. I have worked on projects where JS was a necessity in order to deliver the functionality necessary. It is up to the stakeholders to determine if whatever functionality currently exists through JS is important enough that the site may exclude a small number of visitors. What will that number be? It's difficult to say. According to the stats posted on thses sites: http://www.thecounter.com/stats/2008/April/javas.php http://www.w3schools.com/browsers/browsers_stats.asp approximately 93%-95% of browsers used have JS enabled. However, many of the non-js browsers will be mobile devices and or readers. So, the real number of actual visitors to your site with JS enabled may be slightly higher. Of course, it would be easy enough to gather your own statistics based upon your actual visitors. With a site for a Pizza chain, I don't see any reason that JS would need to be required though.
-
I'm mostly in agreement with tomfmason. Whenever possible the JavaScript should only be used to "enhance" a page. It should not be a requirment to use the page. For example, form validation is a great use of javascript. Of course, there should already be validation on the server-side. But also having validation on the client-side helps the user by not having to submit a form with bad data. If done correctly, JavaScript validation can be added so that it does not affect those with JS disabled. however, there are some times when you want to add some functionality that necesitates JS. But, in my opinion, the predominance of JS enabled browsers means that very, very few users woud be restricted.
-
Here is a quick and dirty solution. The input field should be hidden - I made it a text field for display purposes. There are quite a few things I would do with this if I was going to actually use it, but it should get you going. <html> <head> <script> var rating = 1; function showRating(rateVal) { for (i=1; i<=5; i++) { if (rateVal!=0) { imgSrc = (i<=rateVal)? 'star_on.gif' : 'star_off.gif'; } else { imgSrc = (i<=rating)? 'star_on.gif' : 'star_off.gif'; } document.getElementById('rating'+i).src = imgSrc; } return; } function setRating(rateVal) { rating = rateVal document.getElementById('rateValue').value = rateVal; return false; } </script> <body onload=""> <div id="userrating"> <img src="star_off.gif" id="rating1" onmouseover="showRating(1);" onmouseout="showRating(0);" onclick="setRating(1);" ><img src="star_off.gif" id="rating2" onmouseover="showRating(2);" onmouseout="showRating(0);" onclick="setRating(2);" ><img src="star_off.gif" id="rating3" onmouseover="showRating(3);" onmouseout="showRating(0);" onclick="setRating(3);" ><img src="star_off.gif" id="rating4" onmouseover="showRating(4);" onmouseout="showRating(0);" onclick="setRating(4);" ><img src="star_off.gif" id="rating5" onmouseover="showRating(5);" onmouseout="showRating(0);" onclick="setRating(5);"> </div> <br><br><br><br> <form action=""> <input type="text" name="rateValue" id="rateValue"> <br><button type="submit">Submit</button> </form> </body> </html>
-
OK, now that I see your whole page in context I see what you are talking about. But, I don't think there is any technical solution. The problem lies in the implementation process. I reverted to your original functions and there are two specific problems (one which should have a solution, the other doesn't): For the 2nd password. Assuming the user has changed the 1st password (after the 1st and 2nd had already matched), you could call your original function onfocus of the 2nd field. Then if the values don't still match the class could be changed to indicate that. However, putting an onfocus event on that field is not workign correctly. you have too much code for me to go through it all for debugging. The more troubling issue is the 1st password. Let's say a user changes the first password after the 1st and 2nd had already been matched. Based on the "hint" the green background is supposed to indicate that the password passes the length validation. So, if you hcange the hint color when editing the 1st password, what is the user supposed to infer when the color changes? The hint says nothing about matching the 2nd password. The problem is further exacerbated by the fact that all the hints are hidden except for the field in focus. If the 2nd password field hint was visible when editing the 1st password, you could modify that hint in the user's view so the change would make sense. In my opinioin you are trying to add unnecessary, overcomplicated functionality. However, I do see a quick fix (although i still don't like the entire approach). 1. Revert to your original functions. 2. Create this new function function blankPassword2() { document.o_register.password2.value = ''; document.o_register.password2.parentNode.className = ""; } 3. In the password 1 field add this trigger onchange="blankPassword2();" . Now whenever the user edits the password 1 field, they will be forced to revalidate password 2. That's the only solution I see in the current framework you have.
-
It works for me. I don't have full access to your code so some assumptions will be made. Part of your responsibility is to ensure that you provide complete, accurate details of the problem and what you are trying to accomplish - including any pertinent information. Here is a working test page using the same function I posted above. <html> <head> <style> .welldone { background-color: green; </style> <script type="text/javascript"> function checkPasswords() { var pass1= document.o_register.password; var pass2= document.o_register.password2; if (pass1.value.length > 3 ) { pass1.className = "welldone"; } else { pass1.className = ""; pass2.className = ""; return false; } if (pass1.value == pass2.value) { pass2.className = "welldone"; } else { pass2.className = ""; return false; } return true; } </script> </head> <body> <form name="o_register"> Password 1: <input type="password" onchange="checkPasswords();" name="password" /><br> Password 2: <input type="password" onchange="checkPasswords();" name="password2" /><br> </form> </body> </html>
-
If this is only for class assignments, just download a self-contained Web Server/Database such as XAMPP. Once installed you have a web server with PHP support and a MySQL database right on your desktop.
-
Well, I guess I would ask "when" do you want to validate the passwords. I typically only validate onsubmit of the page. In that case your two functions above are not too relevant. You can validate onchange of the fields. That can be annoying in most cases though. In any case, the solution would be (in my opinioni) would be a single functino that you cann either onchange of one of the two fields or onsubmit of the form. Also, several lines in thiose functions have no use. For example you have some lines that create a variable that is never used. Try this single function: function checkPasswords() { var pass1= document.o_register.password; var pass2= document.o_register.password2; if (pass1.value.length > 3 ) { pass1.className = "welldone"; } else { pass1.className = ""; pass2.className = ""; return false; } if (pass1.value == pass2.value) { pass2.className = "welldone"; } else { pass2.className = ""; return false; } return true; }
-
Just a couple other points: 1. There is no need to specify id in the field list. Since you are passing an empty string I am surmising that the field is an auto-increment field. You don't need to include it in the INSERT statement to work correctly. If those really are your queries you can save a lot of time by creating the query as a variable first. It is also extremely helpful to create your queries as variables as you can display them if there is an error. I know you said no arrays, but this is so much cleaner. <?php if ($Pname=='5_Item_Package'){ for ($i=1; $i<=5; $i++) { $values[] = "('$Cnumber', 'DIFFERENT NAME $i', '$today', '$approved', '$status', '$qty', '$cost', '$included', '$description', '$hr', '$locked' )"; } $query = "INSERT INTO projects (Cnumber, Pname, date, approved, status, qty, cost, included, description, hourly, locked) VALUES " . implode(', ', $values); mysql_query($query) or die (mysql_error() . "<br>Query:<br>$query"); } else {Just one query} ?>
-
I'm not sure I follow you. Are you trying to figure out how to validate the value? For radio buttons I typically create an array of valid values and check if the post'ed value is in the array: <?php $mformat = $_POST['mformat']; $valid_formats = array('TIFF', 'PDF'); if (!in_array($mformat, $valid_formats)) { echo "ERROR: Format '$mformat' is NOT valid"; } else { echo "OK: Format '$mformat' is valid"; } ?>
-
The following will generate a report of records missing first or last names (not tested so there may be syntax errors): <?php $query = "SELECT * FROM byrnjobdb.clients WHERE Firstname IS null OR Firstname='' OR Lastname IS null OR Lastname=''"; $result = mysql_query($query) or die (mysql_error()); if (mysql_num_rows($result)==0) { echo "All records contain first and last names."; } else { echo "Records missing first or last name:<br>\n"; echo "<table>\n"; echo "<tr><td>No.</td><td>First Name</td><td>Last Name</td><td>Company</td></tr>\n;" $no = 0; while ($client = mysql_fetch_Assoc($result)) { $no++; echo " <tr>\n"; echo " <td>$no</td>\n;" echo " <td>".$client['Firstname']."</td>\n;" echo " <td>".$client['Lastname']."</td>\n;" echo " <td>".$client['Company']."</td>\n;" echo " </tr>\n"; } echo "</table>\n"; } ?>
-
Sorry, but that IS the problem isn't it? @Darkmatter5, As Barand suggested there should be no reason to create a Full Name field. You already have the data you can always determine the FullName dynamically when displaying your results (a small function would work great). If you are wanting to find records that are missing first or last name then I would create a display/search for exactly those purposes. Just creating a "full name" value means the secretary needs to back and read each full name to determine is a name is missing. Why not create a report showing just the records with missing required data? Although I also would not suggest creating a full name field, I thought I would post the followng query for learning purposes. The following single query would update all the records in the table in one shot as per your first attempt. UPDATE byrnjobdb.clients SET `FullName` = IF(CompanyName='', CONCAT_WS(' ', FirstName, LastName), CONCAT_WS(' ', FirstName, LastName, 'of', CompanyName) )
-
This is what I call a Doh! moment (we all have them). The problem is you have no WHERE clause on your sub queries. So on every iterration of the loop it is updating ALL THE RECORDS in the table - not just that current record. I am assuming John Smith is the values for first and last name of the LAST record in that table. A better approach would be to do a single query. I know you can do a type of IF/ELSE in a query. You just need to run a single query with an if/else to determine if you want full name to be just first and last or first, last & company.
-
[SOLVED] mysql_num_rows using limit in sql command
Psycho replied to ahs10's topic in PHP Coding Help
Why don't you just ALWAYS use the LIMIT. If there are less records than the limit then it will only pull those. Then just use a mysql_num_rows() after the query to determine how many were actually returned. I don't understand why you need to know the number of records to determine what limit to use. $limit = 5; $query = "SELECT * FROM table LIMIT $limit"; $rcResult = mysql_query($query); $realCount = mysql_num_rows($rcResult); echo "Query limit: $limit<br>Returned count: $realCount"; -
I understand you may be new to PHP, but you are making this much harder than it needs to be by not being very specific. I will state what I think you are trying to do based upon the previous posts. You have two different php files (light.php and dark.php) which determine the background image to show in an index page. You want some logic to determine which file to include using a require_once() function. However, you have not stated "HOW" you are going to determine the value to use to make that choice. I had made an assumption previously that you would pass a value on the URL when calling the index page, such as www.mydomain.com/index.php?type=light In that assumed example the index.php page would hold the content, and the dark.php and light.php scripts wouold be used to detemine the image to show on index.php (as in my first code example above). In the index.php page: <?php //Light will be the default if no value (or invalid value) passed $page_type = ($_GET['type']=='dark') ? 'dark.php' : 'light.php' ; require_once($page_type); ?> However, some statements you have made can be interpreted to mean that dark.php & light.php are two completly different pages - in which case all of this is unnecessary. If the user calls light.php then they will see what's in that page, the same for dark.php. Me: You: That didn't answer the question. Another option that you might not be describing correctly is that you might have the user call dark.php or light.php and each of those pages does a require of the index page. But, again there really isn't enough information to provide relevant help.
-
You don't state how you are passing the value to your index page, but I will assume it is sent on the URL as in my example above. <?php //Light will be the default if no value (or invalid value) passed $page_type = ($_GET['type']=='dark') ? 'dark.php' : 'light.php' ; require($page_type); ?>
-
What does that have to do with PHP? Those are two separate pages, so you do not need any programatical differences to show the different images. They can be statically defined in the HTML if you so choose. Now, if you used a single page and passed a variable to determine the image to show, then your questino would be relevant. Examples: www.website.com/en/page?type=light www.website.com/en/page?type=dark
-
[SOLVED] strikethrough text to normal text (onclick)
Psycho replied to technotool's topic in Javascript Help
You were almost there! Using a single equal sign, even in an IF clause, is treated as an assignment operator. So instead of testing if two values are equal it attemts to assign the 2nd value to the first. When testing to see if two values are equal you need to use TWO equal signs Change both instances of this line if (fieldObj.style.textDecoration!='underline') { To this (note that '!=' changes to '==' if (fieldObj.style.textDecoration=='underline') { -
No i just want someone to fill out a form and it submit to a directory as an hmtl or php file. thats all Isn't that what I just said? Use the input from the user with a template to create an HTML or PHP file?
-
FYI: For the "flat-file" implementation I was not suggesting to use a flat file as a database (although that is another valid option). I meant to use a template and then populate the user values as appropriate and then write the result as an HTML or PHP file.
-
If I am understanding you correctly you want the user to be able to enter the information that will be used as part of the "template" for all the pages on the site. I see two choices: 1. Save the data to a database and create the pages on-the-fly. This allows easy updating of those values at a later time. 2. Use the input to create a flat file PHP script that all the otehr pages use. If the pages rarely change this might be an easier solution, especially if you don't have a database or do not want to learn how to use one.
-
I want to use textbox values on a form without submiting the form
Psycho replied to matudustrauss's topic in Javascript Help
You will need to use JavaScript to access the field value and then submit it through AJAX. -
I don't know that there is going to be an easy solution. There are a ton of variables to be considered when searching for duplicates. There are companies that sell software for a lot of money to do just that so gettng their criteria will not be possible. So, your best bet is to look for a pre-built solution if someone has been kind enough to release something publicly. However, the type of license they released the code under may prevent you from using it for free. You'll just have to check the restritions if you find something. If you can't find something, and assuming you don't want to buy something. your only option is to build a solution or pay someone to build it. If it doesn't have to be PHP, here is a list of applicatins that might work. They range in price from $20 to over $600. The level of effectiveness will most likley be directly proportional to the price. Some may be able to be incorporated in PHP if built to do so.