Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Also, if you want help with a JavaScript problem do not post pre-processed server-side code. There is no way for us to know what is in those included files and variables that may, or may not, be affecting the JavaScript. In this case, since you have absolutely no clue what relevant code to post, you should just post a link to the page.
-
There are many tutorials and ready-made scripts to process file uploads. A simple Google search will get you all you need. There are two methods to validate that a file is of the correct type. You can simply check the extension of the file to ensure it is ".mp3" (make sure to use strtolower()!) and/or you can also detect the file properties to ensure it is an mp3 (lest somebody simply renames the file extension to mp3). That would be done using finfo_file(). As for the ID3 MetaData you could use the class getID3(), which will read all ID3 tags for the file. http://getid3.sourceforge.net/
-
If you were to ask my wife, that probably isn't a good thing.
-
Dynamically create Drop Down list with for current time as default.
Psycho replied to nkosinathi's topic in PHP Coding Help
That's called a ternary operator. It's sort of a shorthand version of an If/Else statement. In this case I am using it to assign a value to $selected. If the condition in the parens is true, then the first value is assigned: ' selected="selected"'. If the condition is false then the second value is assigned: ''. I then use that value to set the appropriate option to selected in the HTML. Here is a illustrative example: $var = ([CONDITION]) ? [TRUE VALUE] : [FALSE VALUE] ; $a = 1; $result = ($a == 1) ? 'The variable $a equals 1' : 'The variable $a does not equal 1'; echo $result; //Output: The variable $a equals 1 $a = 2; $result = ($a == 1) ? 'The variable $a equals 1' : 'The variable $a does not equal 1'; echo $result; //Output: The variable $a does not equal 1 -
moving rows up or down, promoting and demoting, in a database?
Psycho replied to seniramsu's topic in PHP Coding Help
You should NOT be using the primary ID field for the order id field. Changing the attributes of the primary ID to allow duplicates is really bad. Just create another column (e.g. orderInt) to hold the order index value. -
Lot's of problems: 1. There is at least one error in your HTML: Missing the closing quote mark for the name of the checkbox. 2. You gave the fields a name of, well, "name". This is bad because you try to reference the fields via "myform.name.disabled", where "name" is the name of the fields. But, the form has a name property (i.e. "myform") so there is a conflict. 3. a radio button group is multiple elements. you can't enable/disable multiple elements with a single line like that. 4. onchange doesn't work for a checkbox until you exit the field, you want to use onclick <html> <head> <script type='text/javascript'> function enableRadioGroup(groupName, enableState) { var groupObj = document.forms['myform'].elements[groupName]; var groupLength = groupObj.length; for (var i=0; i<groupLength; i++) { groupObj[i].disabled = (!enableState); } enableTextBox(groupObj[0].checked); } function enableTextBox(enableState) { document.forms['myform'].elements['textName'].disabled = (!enableState); } function start() { enableRadioGroup('radioName', false); } onload = start; </script> </head> <body> <form action="" method="post" enctype="multipart/form-data" name="myform"> <br /> the checkbox that determines if the others are active: <input type="checkbox" name="cb" onclick="enableRadioGroup('radioName', this.checked);" /> <br /><br /> <input type="radio" name="radioName" onclick="enableTextBox(this.checked);" /> <input type="text" length="20" name="textName" /><br /> <input type="radio" name="radioName" value="folderone" onclick="enableTextBox(!this.checked);" /><br /> <input type="radio" name="radioName" value="foldertwo" onclick="enableTextBox(!this.checked);" /><br /> <br /> The file:<input type="file" name="image" /> <br /> <input type="submit" name="submit" value="submit" /> </body> </html>
-
And, where does it "take" them. Are you getting any errors? Please understadn in the first problem you had it isn't "taking" them to another page. The mailer.php script encounter an error so it displayed the error on the page and stoped processign any more code (inlcuding the header to redirect to the thanks page).
-
Jeez, I provided a link. Do I need to come to your house to click it for you? I guess you would rather have me give you a fish instead of teaching you how to fish.
-
Dynamically create Drop Down list with for current time as default.
Psycho replied to nkosinathi's topic in PHP Coding Help
You're using a programming language, don't make things difficult on yourself. Use the PHP to create the select lists: <?php $hourSelect = "<select name=\"hour\">\n"; $currentHour = date('H'); for($hour=0; $hour<=23; $hour++) { $hourStr = str_pad($hour, 2, '0', STR_PAD_LEFT); $selected = ($hour==$currentHour) ? ' selected="selected"': ''; $hourSelect .= "<option value=\"{$hourStr}\"{$selected}>{$hourStr}</option>\n"; } $hourSelect .= "</select>\n"; $minuteSelect = "<select name=\"minute\">\n"; $currentMinute = date('i'); for($minute=1; $minute<=60; $minute++) { $minStr = str_pad($minute, 2, '0', STR_PAD_LEFT); $selected = ($minute==$currentMinute) ? ' selected="selected"': ''; $minuteSelect .= "<option value=\"{$minStr}\"{$selected}>{$minStr}</option>\n"; } $minuteSelect .= "</select>\n"; ?> Time: <?php echo $hourSelect; ?>:<?php echo $minuteSelect; ?> -
No, this is a MySQL question. How you create the query is inconsequential to the question of how the query should be formatted. [Moving to appropriate forum]. Besides, the solution has already been provided.
-
i don`t see any rasmus in this thread? I think it was stated he responded in your bug report. http://en.wikipedia.org/wiki/Rasmus_Lerdorf
-
Did use the code I provided so you can verify that the query is what you expect? I'd run that code using one of the values that is not returning the correct results. If the query looks right, try copy/pasting the exact same query in phpmyadmin to see if the results are different. When debugging problems such as this you have to exclude ONE variable at a time. By executing queries manually in phpmyadmin you are validating that THOSE queries are working. You need to run the exact same query in phpmyadmin as the one which is giving you trouble in the application. That is why you should echo the query to the page. ALthough you think you know whatthey queries should be you need to verify that.
-
Help counting the number of a curtain day/s between two dates
Psycho replied to bodycount's topic in PHP Coding Help
Here you go. This function will return an array with weekday names for keys and values as to the number of times that day occurs in the date range (tested): function getWeekDayCount($startDt, $endDt) { $weekdays = array(); $days = round(abs(strtotime($endDt) - strtotime($startDt)) / 86400, 0); $whole_weeks = floor($days/7); $extra_days = $days % 7; for($weekday=0; $weekday<7; $weekday++) { $dayName = date('l', strtotime("$startDt +$weekday days")); $weekdays[$dayName] = $whole_weeks + (($weekday<=$extra_days)?1:0); } return $weekdays; } $start_date = "2010-04-05"; $end_date = "2010-04-15"; $weekdays = getWeekDayCount($start_date, $end_date); print_r($weekdays); Output: Array ( [Monday] => 2 [Tuesday] => 2 [Wednesday] => 2 [Thursday] => 2 [Friday] => 1 [saturday] => 1 [sunday] => 1 ) -
Change this: foreach($_POST['check'] as $value) { $check_msg .= "Services I am interested in: $value\n"; } To this: if(isset($_POST['check']) && is_array($_POST['check'])) { foreach($_POST['check'] as $value) { $check_msg .= "Services I am interested in: $value\n"; } } The problem is the code is trying to run a foreach() loop on a variable ($_POST['check']) that does not exist. Also, added validation to ensure it is an array as well. So, with the new code, if the value doesn't exist or if it is not an array, the foreach() is skipped.
-
This SINGLE query would accomplish the same thing as that code above! UPDATE Persons SET FirstName = REPLACE(FirstName, 'Peter', 'Jammy') WHERE FirstName='Peter is my name' No need to query the database for the records, process the records, and then do an update.
-
UPDATE `table` SET `fieldname` = REPLACE(`fieldname`, 'red', 'blue')
-
Getting the number of days from the selected month in a form
Psycho replied to TeddyKiller's topic in PHP Coding Help
Huh? Not sure what you mean. I guese the code be compacted a little more, but I chose to leave it more compartmentalized. Plus, I added some "nice to have" functionality to ensure theday didn't change when the list length changes. Here' a quick rewrite that shortens the code function setDays() { var dayObj = document.getElementById('day'); var month = document.getElementById('month').value; var year = document.getElementById('year').value; var days = daysInMonth(month, year); while(dayObj.options.length!=days) { if(dayObj.options.length>days) { dayObj.options.length = days; } dayNo = (dayObj.options.length + 1); dayObj.options[dayNo-1] = new Option(dayNo, dayNo); } return; } -
No, I don't think the readonly is a problem. But, I couldn't enter text into those fields otherwise. I was just letting you know what I modified when I tested.
-
Getting the number of days from the selected month in a form
Psycho replied to TeddyKiller's topic in PHP Coding Help
[Moving to JavaScript forum] You will need the year as well otherwise you have to populate 29 for Februrary even when it is not valid. And, if you do that, what's the point of doing this at all? Don't see why you would need/want to use AJAX as the logic can be handled in JS just fine. Sample code <html> <head> <script type="text/javascript"> function daysInMonth(month, year) { var days = 31; if (month == 2) { days=((year%4==0 && (year%100!=0 || year%400==0)))?'29':'28'; } else if (month==4 || month==6 || month==9 || month==11) { days = 30; } return days; } function setDays() { var dayObj = document.getElementById('day'); var month = document.getElementById('month').value; var year = document.getElementById('year').value; var dayIdx = dayObj.options.selectedIndex; var days = daysInMonth(month, year); //No chance in days if(dayObj.options.length==days) { return; } //Too many days, remove some if(dayObj.options.length>days) { dayObj.options.length = days; if (dayIdx < days) { dayObj.options.selectedIndex = dayIdx; } return; } //Not enough days, add some while(dayObj.options.length<days) { dayNo = (dayObj.options.length + 1); dayObj.options[dayObj.options.length] = new Option(dayNo, dayNo); } return; } </script> </head> <body> Month: <select name="month" id="month" onchange="setDays();"> <option value="1">Jan</option> <option value="2">Feb</option> <option value="3">Mar</option> <option value="4">Apr</option> <option value="5">May</option> <option value="6">Jun</option> <option value="7">Jul</option> <option value="8">Aug</option> <option value="9">Sep</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select><br /> Day: <select name="day" id="day"> <option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option> <option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option> <option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option> <option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option> <option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option> <option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option> <option value="31">31</option> </select><br /> Year: <select name="year" id="year" onchange="setDays();"> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> </select><br /> </body> </html> -
whats wrong with this query? How can I fix it
Psycho replied to TeddyKiller's topic in PHP Coding Help
I've not used date_format() in a database query before. but, I do notice that you are using it differently: date_format(event_start, '%l:%i %p') as fmt_date [uses the letter L and and the letter I] date_format(event_end, '%1:%1 %p') as end_date [uses the number 1 both times] -
Don't think so. I tried his search and it workes fine for "Dictionary of ", but as soon as I add the "L" it didn't find that record. And, just searching for "of" works. But searching on "Law" fails to find the record. And, searching just on the letter "L" does work. Very odd indeed.
-
First, echo your query to the page to ensure it has the value that you expect: $search=$_POST["search"]; $searchtype=$_POST["searchtype"]; $query = "SELECT * FROM items WHERE $searchtype LIKE '%$search%'"; //Debugging info echo "Search: {$search}<br>\n"; echo "Search Type: {$searchtype}<br>\n"; echo "Query: {$query}<br>\n"; //End debugging $result = mysql_query($query);
-
See Example #2 in the manual to remove slashes if magic quotes is on at runtime: http://php.net/manual/en/security.magicquotes.disabling.php
-
I would add that I *think* you are taking the wrong approach in your comparisons. Instead of checking if r1 < r2 and r3 you should be checking if r1 is equal to the minimum time. Otherwise if you had two minimum times that were equal - neither would be in red. This may be a little more efficient and accurate: $roundMin = min($r['q1'], $r['q2'], $r['q3']); //Remove 'x' $r['q1'] = str_replace('x', '', $r['q1']); $r['q2'] = str_replace('x', '', $r['q2']); $r['q3'] = str_replace('x', '', $r['q3']); //Format minimum(s) in red if ($r['q1']==$roundMin) { $r['q1'] = "<font color=red>{$r['q1']}</font>"; } if ($r['q2']==$roundMin) { $r['q2'] = "<font color=red>{$r['q2']}</font>"; } if ($r['q3']==$roundMin) { $r['q3'] = "<font color=red>{$r['q3']}</font>"; }
-
You can't print something that doesn't exist. Therefore, if the computer has not opened/loaded the content for the page, it can't print the page. However, there is one "hack" that I can think of by using some CSS properties. Using CSS you can set style properties for elements to be different based upon the "media" that the content is displayed in. For example, you can have page elements displayed differently in a browser than in a phone. One of the supported media types is the "print" media. This means you can have a page displayed ina browseer differently than it prints. This is what you could do. Create a DIV on the parent page which has a display=none default setting, but a display=inline for the print media type. Then for the rest of the content in the parent page, do the exact opposite. display=inline is the normal setting so you don't need to declare that, but give them a display=none for the print media. What this means is that when viewed in a browser the "print" div will be invisible, but when the page is printed, the contents of the div is the only thing that will be printed. Then it is just a matter of modifying your javascript to load the content you want to print into the DIV before initiating the print dialog for the parent page. Of course, this means the user will not be able to print the parent page as they see it. There are several posts on these forums regarding the media attributes for styles (a couple of which I have provided examples to) so you can search for those if you need more info.