Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Re-populating a DropDown Menu and selecting the correct value
Psycho replied to acctman's topic in PHP Coding Help
Okay, this <%m_month%> has no meaning to me. I would assume it would either be a variable such as $m_month or a constant such as m_month. What are the tags <% and %> supposed to represent? I've never seen that before. Show me how you would echo that in your code. -
Re-populating a DropDown Menu and selecting the correct value
Psycho replied to acctman's topic in PHP Coding Help
What is <%m_month%> exactly? You stated it was a variable, so I thought you had incorrecty typed that and you really meant that <%m_month%> was a variable such as $m_mouth (which is what I included in the code above). $selected = ($m_month == $month_id) ?' selected="selected"':''; If it's a constant then use it as such $selected = (m_month == $month_id) ?' selected="selected"':''; -
Where is $temp defined in the first script?
-
Re-populating a DropDown Menu and selecting the correct value
Psycho replied to acctman's topic in PHP Coding Help
$months = array( 1 => 'January', 2 => 'February', 3 => 'march', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'Octobner', 11 => 'November', 12 => 'December' ); echo "<select name=\"add[month]\">\n"; foreach ($months as $month_id => $month_name) { $selected = ($m_month == $month_id) ?' selected="selected"':''; echo "<optiojn value=\"$month_id\">$month_name</option>\n"; } echo "</select>\n"; -
isset() merely tells you if the variable has been defined, not whether it has a value or not. So, you could set the value to an empty string or a null value and isset() will return true. Try using !empty()
-
No need to trim anything <?php while ($row_mapdirections = mysql_fetch_assoc($mapdirections)) { $outputAry[] = $row_mapdirections['name'] . '@' . $row_mapdirections['lat'] . ', ' . $row_mapdirections['lon']; } echo implode(' to: ', $outputAry); ?>
-
You will need to determine some more explicit rules on how you would display the date. "24-26 Apr 2009" or "24 Apr - 26 Apr 2009." Is fine if the date span does not go from Dec 31. to Jan. 1. query = "SELECT society, venue, dates, enddate FROM showdates where dates between CURRENT_DATE and CURRENT_DATE + interval 1 year ORDER BY dates ASC"; $result = mysql_query($query); while(list($society, $venue, $dates, $enddate)= mysql_fetch_row($result)) { list($start_year, $start_month, $start_day)=split("-",$dates); if (empty($enddate)) { //No end date. Show just the start date $dates = date('j M Y', mktime(0, 0, 0, $start_month, $start_day, $start_year)); } else { //There is an end date list($end_year, $end_month, $end_day)=split("-",$dates); $dates = $start_day.' '.date('M', $start_time); if ($start_year!=$end_year) { //Start and end have different years $dates .= " $start_year"; } $dates .= ' - ' . $end_day.' '.date('M', $end_time).' '.$end_year; } echo $dates; } //OUTPUT: // //One date: // 24 April 2009 //Two dates, same year: // 24 Apr - 13 Mar 2009 //Two dates, different year // 24 Dec 2009 - 3 Jan 2010 NOTE: Not tested, but the logic should be good.
-
One thing I'll throw out - although it is implied but not explicitly stated above - you should validate and sanitize AND and ALL information comng from the client. For example I have seen instances where no validation was performed on a certain field because a select field was used on the input form and the person writing the code assumed the select field would prevent other values. There is nothing preventing a user from creating their own form and posting it with any values they want. So check everything even if the form would prevent them from sending unknoiwn values: select fields, hiddent fieds, checkbox values, etc. Also should validate cookie values as well.
-
Ah, I had a couple errors. <html> <head> <script type="text/javascript"> function showElement(layer){ var layerList = new Array('Artist','Music','Business','Events','Stories','Food'); for (var i=0; i<layerList.length; i++) { document.getElementById(layerList[i]).style.display = (layer==layerList[i]) ? 'block' : 'none' ; } } </script> </head> <body> <div id="Artist" style="background-position:top;">ARTIST</div> <div id="Music" style="display:none;background-position:top;">MUSIC</div> <div id="Business" style="display:none;background-position:top;">BUSINESS</div> <div id="Events" style="display:none;background-position:top;">EVENTS</div> <div id="Stories" style="display:none;background-position:top;">STORIES</div> <div id="Food" style="display:none;background-position:top;">FOOD</div> <br><br><br><br><BR><BR> <a href="#" onclick="showElement('Artist');">Artist</a><br> <a href="#" onclick="showElement('Music');">Music</a><br> <a href="#" onclick="showElement('Business');">Business</a><br> <a href="#" onclick="showElement('Events');">Events</a><br> <a href="#" onclick="showElement('Stories');">Stories</a><br> <a href="#" onclick="showElement('Food');">Food</a><br> </body> </html>
-
Post the HTML for the divs.
-
Hmm... wouldn't a more efficient way be the right way? Do some research on Database Normalization (thousands of references out there) and learn what is meant be a relational database. Without using the "related" functionality within a database you are left with nothing more than glorified spreadsheets.
-
All I can say is WTF?! First, there should NOT be separate tables for each conference. There should be a table which lists the conferences then one table for all "teams" which holds specific, one-to-one data for the teams and each team would have a foreign key to the conferences table. However, if you decide not to do it the right way, you should be able to get the results you want using UNION. Althugh I'm not 100% sure you can use a sort on a UNION. <?php $path = ""; $title = "Test"; $rank = "yes"; //$login = "yes"; $admin = "yes"; include ($path."main/include/cons/head.php"); $query = "SELECT * FROM `Atlantic Coast Conference` UNION SELECT * FROM `Big 12` UNION SELECT * FROM `Big East` UNION SELECT * FROM `Big 10` UNION SELECT * FROM `Conference USA` UNION SELECT * FROM `Independents` UNION SELECT * FROM `Mid-American` UNION SELECT * FROM `Mountain West` UNION SELECT * FROM `Pac 10` UNION SELECT * FROM `SEC` UNION SELECT * FROM `Sun Belt` UNION SELECT * FROM `WAC` ORDER BY team_name"; $result = mysql_query($query) or die (mysql_error()); while ($record=mysql_fetch_assoc($result)) { echo implode(' - ', $record) . "<br>\n"; } include ($path."main/include/cons/foot.php"); ?>
-
Try this <script type="text/javascript"> function showElement(layer){ var layerList = new Array('Artist','Music','Business','Events','Stories','Food'); for (var i=0; i<layerList.length; i++) { document.getElementById(layer).display = (layer==layerList[i]) ? 'block' : 'none' ; //This section may not be needed - try setting the //background position to top for all divs on page load if (layer==layerList[i]) { document.getElementById(layer).backgroundPosition = 'top'; } } } </script>
-
Hmm, ok after a little trial and error I found a solution. Just put BOTH the text and the link in the table cell and alternate their display states so only one is displayed at a time. Example script <html> <head> <style> .kalender_vak_hover { background-color:#ffffff; } .kalender_dag_van_maand { background-color:#000000; } </style> <script type="text/javascript"> function vak_handle(actie, vak_obj) { document.getElementById(vak_obj.id+'-text').style.display = (actie)?'none':''; document.getElementById(vak_obj.id+'-link').style.display = (actie)?'':'none'; vak_obj.style.color = (actie) ? '#000000' : '#ffffff'; vak_obj.className = (actie) ? 'kalender_vak_hover' : 'kalender_dag_van_maand'; } </script> </head> <body> <table border="1"> <tr> <td id="cell1" onmouseover="vak_handle(true, this);" onmouseout="vak_handle(false, this);" style="color:#ffffff;" class="kalender_dag_van_maand"> <span id="cell1-text"> 100 </span> <span id="cell1-link" style="display:none;"><a href="#">Link1</a></span> </td> <td id="cell2" onmouseover="vak_handle(true, this);" onmouseout="vak_handle(false, this);" style="color:#ffffff;" class="kalender_dag_van_maand"> <span id="cell2-text"> 200 </span> <span id="cell2-link" style="display:none;"><a href="#">Link2</a></span> </td> </tr> </table> </body> </html>
-
Well, if the user hasn't navigated to another page in 15 minutes they their session will expire in another 5 minutes (assuming a 20 minute session timeout). The session doesn't get updated if the user doesn't make another request from the server (i.e. page load). Now that method does have some drawbacks. 1) Would not account for a user who has the site open in multiple windows and 2) Does not account for AJAX request. But for #2 you could simply reset the counter on the user side. I took a look at the JS code for a site I user that does what you ask. It looks as if the code utilizes a cookie to track the session timeout. I would assume it resets the cookie on each page hit. Then the javascript checks the cookie periodically and alerts the user that the session will expire and if it does expire directs the browser to an appropriate page. That would solve provlem #1 above, but I don't think that would work for pages that use AJAX - if you use that.
-
Showing the code of what you have so far would be helpful.
-
Well, the debugging code shows that the problem is not with the unlink() but with your forms. You have TWO different forms. Only ONE form can be submitted!!! So the if condition $_POST['doaction']=='confirm'.'delete' will never return true. Try this: <?php //select directory //$folders = (ftp_nlist($conn,"path to projects")); $folders = array('one','two','three','four','five'); echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; //Create Folders select list echo "<select name=\"folder\">\n"; for ($i=2;$i<count($folders);$i++) { $selected = ($folders[$i]==$_POST['folder'])?' selected="selected"':''; echo "<option value=\"{$folders[$i]}\"$selected>{$folders[$i]}</option>\n"; } echo "</select>\n"; echo '<input name="doaction" type="Submit" value="select_folder"></form>'; if ($_POST['doaction']=='select_folder' || $_POST['doaction']=='delete_image') { //There should be some code here to //get the image names for the selected folder //Select image to delete echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">\n"; echo "<input type=\"hidden\" name=\"folder\" value=\"{$_POST['folder']}\">\n"; echo "<select name=\"images\">\n"; for ($i=2;$i<count($images);$i++) { echo "<option>{$images[$i]}</option>\n"; } echo "</select>\n"; echo "<input name=\"doaction\" type=\"Submit\" value=\"delete_image\">\n"; echo "</form>\n"; } //delete image if ($_POST['doaction']=='delete_image') { $file = "../userfiles/images/projects/{$_POST['folders']}/{$_POST['images']}"; if (file_exists($file)) { unlink($file); echo "Deleted '$file'"; } else { echo "The file '$file' does not exist."; } } ?>
-
Need more information about the CSV. Are there name/value pairs on each line or what. If the name/value pairs are on each line such as: name1=value1 name2=value2 name3=value3 Then that is a simple procedure: $data = file('path/to/csvfile.csv'); foreach ($data as $line) { $nameValue = explode('=', $line); $name = trim($nameValue[0]); $value = trim($nameValue[1]); echo "Variable: $name, Value: $value<br />"; } //Output //Variable: name1, Value: value1 //Variable: name2, Value: value2 //Variable: name3, Value: value3
-
You don't need to check every minute. I'm not even sure JavaScript can determine if the session is active. Just create a JavaScript function to initiate based upon the session timeout set on the server using the setTimeout() function and have it start on page load. For example, if the session timeout is 20 minutes. You could do a setTimeout() to call a function at 15 minutes with an alert telling the user that there session will expire in 15 minutes giving them the option to keep the session active. That could be achieved by having a positive response either refresh the page, or having an AJAX call to an empty page. The latter option is better in my opinion because you don't have to worry about saving the user's data before a refresh. Then also have a setTimeout() at 20 minutes to direct the page to the login page.
-
Based upon what I see, I *think* this may work, but I can't be sure without testing. Change the last function as follows: // Creates the HTML for the actual calendar part of the chooser DateChooser.prototype.createCalendarHtml = function() { var result = "\r\n<table cellspacing=\"0\" class=\"dateChooser\">" + "\r\n <tr><th>N</th><th>P</th><th>U</th>" + "<th>S</th><th>C</th><th>P</th><th>S</th></tr>\r\n <tr>"; //=======BEGIN MODIFIED CODE============== // Fill up the days of the week until we get to the first day of the month var firstDay = this._date.getFirstDayOfMonth() - 1; if (firstDay == -1) { firstDay = 6; } var lastDay = this._date.getLastDayOfMonth() - 1; if (lastDay == -1) { lastDay = 6; } //=======END MODIFIED CODE=============== if (firstDay != 0) { result += "<td colspan=\"" + firstDay + "\"> </td>"; } // Fill in the days of the month var i = 0; while (i < this._date.getDaysInMonth()) { if (((i++ + firstDay) % 7) == 0) { result += "</tr>\r\n <tr>"; } var thisDay = new Date( this._date.getFullYear(), this._date.getMonth(), i); var js = '"dateChooserSetDate(\'' + this._input.getAttribute('id') + "', '" + thisDay.dateFormat(this._format) + '\');"' result += "\r\n <td class=\"dateChooserActive" // If the date is the currently chosen date, highlight it + (i == this._date.getDate() ? " dateChooserActiveToday" : "") + "\" onClick=" + js + ">" + i + "</td>"; } // Fill in any days after the end of the month if (lastDay != 6) { result += "<td colspan=\"" + (6 - lastDay) + "\"> </td>"; } return result + "\r\n </tr>\r\n</table><!--[if lte IE 6.5]><iframe></iframe><![endif]-->"; } You will probably want to change the column headers where the variable result is first defined. But, I'm not sure if you did that already or not since you apparently have letters for days of the week from a different language.
-
It would be easier to provide a solution if you posted a link to a working page or the code for a working page.
-
Than maybe that first IF is never meeting a true condition. Try this: if ($_POST['doaction']=='confirm'.'delete') { $file = "../userfiles/images/projects/{$_POST['folders']}/{$_POST['images']}"; if (file_exists($file)) { unlink($file); echo "Attempting to delete '$file'"; } else { echo "The file '$file' does not exist."; } } else { echo "No post data"; }
-
Did you check the actual HTML code? It could be that the problem has to do with certain style properties. If the [br] tags are in the actual html code and just not rendered how you want, then that is NOT a PHP problem.
-
That script is a timebomb waiting to happen. Someone could use it to delete any file on your website by using relative paths in the values! You need to have some very strong, comprehensive validation of those values. But, specifically to address your problem, I'm guessing that if the values are correctly passed then the problem is with that last .' ' that is appended to the end of the path. Why are you adding a space? As far as I know it is impossible to have a file name with a space at the end. So, remove that and add some debugging code to see what is happening until you get the script working. if ($_POST['doaction']=='confirm'.'delete') { $file = "../userfiles/images/projects/{$_POST['folders']}/{$_POST['images']}"; if (file_exists($file)) { unlink($file); } else { echo "The file '$file' does not exist."; } }
-
You need to be more specific. When you say it "doesn't appear tobe working" - what does that mean. It is either owrking or not. If it is not working, in what way? Do you get error messages? Is it returning the wrong values? What? If I copy/paste the code I submitted above into a new htm page it works perfectly in IE and FF. SO I have no idea what you have done differently. As for similar code in PHP I don't know how to respond. Simply take the three POSTed values, add them together and test if they equal 12.