-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Give this a try (note: using disabled for an <option> tag works in browser other than IE and in IE8) - <script type="text/javascript"> function disableselected(selectobj){ var select2=document.getElementById("sel2"); var select3=document.getElementById("sel3"); // if the first choice is changed, reset the 2nd and 3rd select lists for (var i=0; i<selectobj.options.length; i++){ select2.options[i].disabled=false; // clear any exiting disabled options select3.options[i].disabled=false; // clear any exiting disabled options } select2.options[0].selected=true; // clear any exiting selection (select the Make Your Pick option) select3.options[0].selected=true; // clear any exiting selection (select the Make Your Pick option) // if you didn't pick the Make Your Pick, disable the same choice in the 2nd and 3rd select lists if(selectobj.selectedIndex != 0){ select2.options[selectobj.selectedIndex].disabled=true; select3.options[selectobj.selectedIndex].disabled=true; } } function disableselected2(selectobj){ var select3=document.getElementById("sel3"); // if the second choice is changed, reset the 3rd select list for (var i=0; i<selectobj.options.length; i++){ if(selectobj.options[i].disabled == false){ select3.options[i].disabled=false; // clear any exiting disabled options } else { select3.options[i].disabled=true; // set disabled if the current menu's option is also disabled } } select3.options[0].selected=true; // clear any exiting selection (select the Make Your Pick option) // if you didn't pick the Make Your Pick, disable the same choice in the 3rd select list if(selectobj.selectedIndex != 0){ select3.options[selectobj.selectedIndex].disabled=true; } } </script> <form> <select onclick="disableselected(this)"> <option>Make Your Pick</option> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> <select id="sel2" onclick="disableselected2(this)"> <option>Make Your Pick</option> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> <select id="sel3"> <option>Make Your Pick</option> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> </form>
-
Mysql update query isn't getting $_POST data
PFMaBiSmAd replied to VictorVonKai's topic in MySQL Help
The code you posted contains fatal parse/syntax errors due to putting array variables inside of a string. You would need to put {} around each {$_POST[...]} variable and you should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini (or a local php.ini or a .htaccess file) so that all the errors that php detects will be reported and displayed. You will save a ton of time. Also, since the values are apparently text, you would need to enclose them in single-quotes inside of the query to prevent sql syntax errors. mysql_query("UPDATE DB SET value1 = '{$_POST['data1']}' WHERE value = '{$_POST['data2']}'"); -
You could also remove the option from the list (adding it back if they change their selection would take a little coding to accomplish.) Ref: http://w3schools.com/jsref/met_select_remove.asp
-
The following demonstrates basically how to do this (assuming you are not using IE browsers) - <script type="text/javascript"> function disableselected(selectobj){ var nextselect=document.getElementById("sel2"); // reference the next select menu nextselect.options[selectobj.selectedIndex].disabled=true; // disable the same element in the next select that was just selected in the first select } </script> <form> <select onChange="disableselected(this)"> <option>Make Your Pick</option> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> <select id="sel2"> <option>Make Your Pick</option> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> </form> The above code leaves any items disabled, so if you change your choice in the first drop-down, each corresponding item in the second drop-down will become disabled. To correct this you would need to loop through all the elements in the second drop-down and set the .disabled element = false before you set the newly selected one to true.
-
You can also get the selectedIndex from the current select menu and use that to disable the same position in another select menu. Ref: http://www.javascriptkit.com/jsref/select.shtml
-
Here is a specific example of using an id that would probably be helpful - http://www.w3schools.com/js/tryit.asp?filename=try_dom_option_disabled_id If the <option that is selected has an id that relates it to the id of the option that should be disabled, it should be fairly easy to write some generic code to do this. Something like id = 'opt1a' and id 'opt1b'. If option opt1a is the id that gets selected, you can set the disabled attribute for id = 'opt1b'.
-
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306771.0
-
There is a disabled attribute for the <option > tag - http://w3schools.com/tags/att_option_disabled.asp You can easily come up with some javascript to set that attribute whenever a choice is made on an earlier <select> menu. And since this is a client side problem, moving thread the Javascript forum section ...
-
how to break if something doesn't exist (This should be easy)
PFMaBiSmAd replied to Lucky2710's topic in PHP Coding Help
Joining your user table with the cfb table, only to get a list of users that have picks so that you can use that list to re-query your cfb table inside of a loop/function is a huge waste of time and will take three times more code than you need. Someone already showed you in one of your other threads on this problem how to get the count of correct picks for each user. All you really need to do is join that with your user table to get the corresponding user names. One query and a little code to iterate over the results of the query. -
Posts are generally not deleted in programming help forums because the problem and the solution could have helped someone else.
-
The following link is the definition of what mysql_query() returns, which I repeated in the post I wrote above - http://php.net/mysql_query If you are not gong to read and follow the information that exists for a programming language, you will not be able to write code that works.
-
mysql_query() for a SELECT query either returns a result resource if the query executed without error or it returns a FALSE value if the query fails due to an error. A query that matches zero rows is a successful query and returns a result resource. Your if/else code - if ($result) { echo"Access"; } else { echo"No Access"; } will echo "Access" as long as the query executes without any errors, even if it matches zero rows. You would want to use mysql_num_rows() inside the TRUE branch of the if/else statement to find out if the query returned any rows. Also, your query makes little sense. You are only asking if there are any rows with Access='1'. Do you in fact want to test if a specific visitor has his access value set to 1?
-
This is the basic query that does what you are asking (user_id = 1 is the master record) - $query = "SELECT user.user_id,user.game_id,COUNT(*) as Total FROM Cfb as master JOIN Cfb as user ON master.game_id = user.game_id AND master.pick = user.pick AND master.user_id = 1 GROUP BY user.game_id, user.user_id"; This gets all the results for all the games and all the users. As is, it would return results like this - user_id game_id Total 1 1 12 11 1 6 61 1 12 1 2 12 11 2 6 61 2 11 user_id 1 is the master, so he of course matches all 12 in both games. user_id 11 got 6 correct in both games. user_id 61 got 12 correct in game 1 and 11 correct in game 2. If you put in a WHERE clause (goes in before the GROUP BY clause) you can determine what you want to operate on. If you add WHERE user.game_id = 2, it will return only the results for game 2 - user_id game_id Total 1 2 12 11 2 6 61 2 11 If you change the WHERE clause to user.user_id = 61, it will return only the results for user 61 - user_id game_id Total 61 1 12 61 2 11 And of course any other valid usage (WHERE user.game_id = 2 AND user.user_id = 61) - user_id game_id Total 61 2 11
-
You can generally do processing like this directly in a query. I would - 1) Select rows where the user's pick and game_id matches the master record, 2) Then GROUP BY the user_id, and 3) Use COUNT() in the SELECT list to give you the number of rows in each group. This would tell you how many matching rows each user has. This will work no matter how many users you select, from a single one to all of them (simply don't put the user_id as a condition in the WHERE clause.)
-
Yes, but if you cannot even find your own simple php syntax errors because you cannot see them, you are not gaining anything by writing code like that.
-
Ummm. You can search and replace the tags to fix the problem forever in any piece of code.
-
Don't use the short open tags. It results in non-portable code because you won't always be on a server where you will have the ability to turn the setting on. You have probably already wasted 10x times more time messing with this on one server setup than you ever saved in typing time by leaving off three letters a few times on a page. If you simply use full opening tags, you won't ever need to waste any of your time messing with this problem when you put your code onto a different server. And if you ever expect to publish any of your code for others to use, you CANNOT use short open tags in it because the people using that code won't necessarily have the ability to turn on the setting on their server.
-
If you use the query I posted (adding event = 'Registration' AND to the WHERE clause), for the data you posted it returns 3 morning and 1 night result.
-
Someone already posted how to make the query that I posted work with a Unix Timestamp - SELECT sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '06:00:00' AND '11:59:59' THEN 1 END) AS morning , sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '12:00:00' AND '17:59:59' THEN 1 END) AS afternoon , sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '18:00:00' AND '23:59:59' THEN 1 END) AS evening , sum(CASE WHEN TIME(FROM_UNIXTIME(event_time)) BETWEEN '00:00:00' AND '05:59:59' THEN 1 END) AS night FROM your_table WHERE FROM_UNIXTIME(event_time) BETWEEN '2010-07-01 00:00:00' AND '2010-08-05 23:59:59';
-
If your data was stored as a mysql datetime or mysql timestamp (not to be confused with a Unix Timestamp), the following query does what you are after - SELECT sum(CASE WHEN TIME(date_time) BETWEEN '06:00:00' AND '11:59:59' THEN 1 END) AS morning , sum(CASE WHEN TIME(date_time) BETWEEN '12:00:00' AND '17:59:59' THEN 1 END) AS afternoon , sum(CASE WHEN TIME(date_time) BETWEEN '18:00:00' AND '23:59:59' THEN 1 END) AS evening , sum(CASE WHEN TIME(date_time) BETWEEN '00:00:00' AND '05:59:59' THEN 1 END) AS night FROM your_table WHERE date_time BETWEEN '2010-07-01 00:00:00' AND '2010-08-05 23:59:59'; You could use the mysql FROM_UNIXTIME() function to get your Unix Timestamps onto DATETIME values in the query.
-
Does the count for the 4 time periods accumulate for each day in the date range or is the count for the 4 time periods kept separate for each day in the date range?
-
If you revisit your last thread about your code, you will find that your $enddate1 = strtotime($enddate."11:59:59"); ... calculations are not producing the value you think they are. $enddate is the next day, so that is actually finding everything up to noon the next day, not the current day.
-
If an event during a month exists, add month to list
PFMaBiSmAd replied to Eiolon's topic in PHP Coding Help
Assuming your data is in a database table, the following query will return the month names present for a range of dates you are looking for (this assumes that the range of dates is less then one year) - SELECT MONTHNAME(your_date_column) as mn FROM your_table WHERE your_date_column BETWEEN 'some_start_date' AND 'some_end_date' ORDER BY your_date_column The month name would be available in the data you retrieve, something like $row['mn'] -
Finding Consecutive IP addresses in a LARGE array
PFMaBiSmAd replied to CarmenH's topic in PHP Coding Help
If each set of 8 consecutive ip addresses you are trying to find start on a bit boundary such that you could mask off the lower three bits and if all the remaining bits are the same, they are in the same group of 8, you can do this by - 1) Either convert the IP address to integers or only operate on the last octet of the IP address. 2) Mask off the lower three bits using the & bitwise operator and the correct mask. You can form a mask by using -1 ^ 8 (-1 xor . This will produce a mask of 1111 1111 1111 1111 1111 1111 1111 1000. 3) Use array_count_values() to combine and count the values. 4) Any results from array_count_values() equaling 8 would mean that all eight ip addresses in that group were present. For example, if you had these values somewhere in your original data (order does not matter) - 192.168.1.232 192.168.1.233 192.168.1.234 192.168.1.235 192.168.1.236 192.168.1.237 192.168.1.238 192.168.1.239 After applying & with the mask you would have - 192.168.1.232 192.168.1.232 192.168.1.232 192.168.1.232 192.168.1.232 192.168.1.232 192.168.1.232 192.168.1.232 After array_count_values() you would have - [192.168.1.232] => 8 The actual matching range would be from that IP address through and including that address + 7 -
Actually, I edited my post above. The calculations are not correctly using the right day(s). And if you would store your data using a DATETIME data type, it would be much clearer and would result in simpler and cleaner code.