Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. I would have to see how you implemented the script. It works fine within the code I posted above using your exact same select list.
  2. <?php //Force browser to no cache the page header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); //Set some vars $slaStatus = ""; $slaStatusID = 0; $statusFile = "slaStatus.txt"; $options = array('Missed SLA', 'Made SLA'); //Check if new status was posted if (isset($_POST['slaStatus'])) { //Set the status id and status string from post $slaStatusID = $_POST['slaStatus']; $slaStatus = "Status: " . $options[$slaStatusID]; //Write status id to file $fh = fopen($statusFile, 'w') or die("can't open file"); fwrite($fh, $slaStatusID); fclose($fh); } else if (is_file($statusFile)) { //Set the status id and status string from file $slaStatusID = file_get_contents($statusFile); $slaStatus = "Status: " . $options[$slaStatusID]; } else { $slaStatus = "SLA Status has not been set"; } ?> <html> <body> <div><?php echo $slaStatus; ?></div> <form name="slaForm" action="" method="POST"> <select name="slaStatus" onchange="disp_text();"> <?php foreach($options as $id => $value) { $selected = ($slaStatusID==$id)?' selected="selected"' : ''; echo " <option value=\"$id\"{$selected}>{$value}</option>\n"; } ?> </select> <br /> <button type="submit">Change SLA Status</button> </form> </body> </html>
  3. The line I posted is corrected below. As for how/where you are saving it, I guess I'm confused as to what the pupose it. If you are not using the value for anything then what is the point of saving the value? You need to save the value somewhere. If you want it saved for when you come back to the site, then sessions will not work. Does the value need to be saved for "everyone" or will the saved value be different for different people. A second solution would be to use a cookie, but that value would be different for each user/pc that accesses the page. Otherwise you would need to save to a database or to a flat file. But, since the value isn't used for anything I don't see the point. $selected = ($_SESSION['mylist']==$value)?' selected="selected"' : '';
  4. Well, what do you mean by "until I come back and change it"? What are you doing with the value when you submit the page? You should be using/saving it somewhere. Based upon where you are saving that valule the solutino would be slightly different. Here's an example assuming the value is saved to a session value: $options = array('Made SLA', 'Missed SLA'); echo "<select name=\"mylist\" onchange=\"disp_text();\">"; foreach($options as $value) { $selected = ($_SESSION['mylist']==$value)?' selected="selected" : ''; echo " <option value=\"$value\"{$selected}>{$value}</option>\n"; } echo "</select>\n";
  5. Here's a generic function that you could use for multiple things: <html> <head> <script> function moveSelectOpt(selID, step) { var selObj = document.getElementById(selID); var newID = (selObj.selectedIndex + step); if (newID>=1 && newID<=(selObj.options.length-1)) { selObj.selectedIndex = newID; } else { selObj.selectedIndex = (newID<=1) ? (selObj.options.length-1): 1 ; } return; } </script> </head> <body> <select name="time" id="time" style="width:150px"> <option>Select Time</option> <option value="9:00">Morning</option> <option value="12:00">Afternoon</option> <option value="16:00">Evening</option> <option value="22:00">Late</option> </select><br> <a href="#" onclick="moveSelectOpt('time', 1);">Next Time</a> <a href="#" onclick="moveSelectOpt('time', -1);">Previous Time</a> </body> </html>
  6. Yes, you can stack images on top of each other, you would use layers in CSS, but why? If the images aren't transparent so you can see through them, then you can only see the top image (or at worst you would see edges of the lower images sticking out from the top). It would be simpler to just swap out the image on the top. If it is an issue of a time delay to display the changed image, then just load all the images and change the display properties. Can you give a little more explanation as to what you are trying to acheive and the problem with the code you posted above?
  7. The function "changeModel()" represents your onchange function for the select list. Edit accordingly for your setup: <html> <head> <script type="text/javascript"> var models = new Array(); models['Chrysler'] = ['Pacifica', 'PT Cruiser', 'Sebring']; models['Ford'] = ['Ranger', 'Taurus', 'Mustang']; models['GMC'] = ['Acadia', 'Sierra', 'Yukon']; function changeMake(make) { var modelList = models[make]; changeSelect('model', modelList, modelList); document.getElementById('model').disabled = false; document.getElementById('model').onchange(); } function changeModel(modelValue) { document.getElementById('output').innerHTML = modelValue; return; } function changeSelect(fieldID, newValues, newOptions) { selectField = document.getElementById(fieldID); selectField.options.length = 0; if (newValues && newOptions) { for (i=0; i<newValues.length; i++) { selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]); } } } </script> </head> <body> Make:<br> <input type="radio" name="make" value="Chrysler" onclick="changeMake(this.value);"> Chrysler<br /> <input type="radio" name="make" value="Ford" onclick="changeMake(this.value);"> Ford<br /> <input type="radio" name="make" value="GMC" onclick="changeMake(this.value);"> GMC<br /> <br> Model: <select name="model" id="model" onchange="changeModel(this.value);" disabled="disabled"> <option> -- Select a Make -- </option> </select> <br><br> Output: <span id="output"></span> </body> </html>
  8. You could use Regular Expression. But, I think what you might gain in compact code you would lose in "efficiency" of the code.
  9. I made a last minute change in some variable names and didn't get them all correct. Change the last loop as follows: $output = ""; for($idx=0; $idx<13; $idx++) { $output .= "<tr>\n"; $output .= $td[$idx]; $output .= $td[$idx+13]; $output .= "</tr>\n"; } Still not tested, so there may be more minor errors. As for the error messages, the line numbers refer to the PHP file NOT the HTML output.
  10. And, where did you ask for that? I do like helping people, but there's nothing more frustrating than taking the time to help someone only to have them ask for something different once you provide what they originally asked for. The code below should get you what you want (not tested). <?php $conn = mysql_connect('localhost','hidden', 'hidden') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('hidden', $conn) or trigger_error("SQL", E_USER_ERROR); //Query ALL the records ordered by make $query = "SELECT tblmake.make, tblmake.url, COUNT(tblmodel.modelid) AS model_count FROM tblmake LEFT JOIN tblmodel ON tblmake.makid = tblmodel.makeid GROUP BY tblmake.makid ORDER BY tblmake.make ASC"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); $total_records = mysql_num_rows($result); if($total_records > 0) { //There were results, let's display them $letters = array ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $row = mysql_fetch_assoc($result); foreach($letters as $idx => $letter) { $no_makes_in_letter = true; $td[$idx] .= "<td><h1><a name=\"$letter\">$letter</a></h1><br />\n"; while (substr($row['make'], 0, 1) == $letter) { $no_makes_in_letter = false; $td[$idx] .= "<a href=\"{$row['url']}\">{$row['make']}</a> ({$row['model_count']})<br />\n"; if (!$row = mysql_fetch_assoc($result)) { break; } } if($no_makes_in_letter) { $td[$idx] .= "None<br />\n"; } $td[$idx] .= "</td>\n"; } $output = ""; for($i=0; $idx<13; $i++) { $output .= "<tr>\n"; $output .= $td[$idx]; $output .= $td[$idx+13]; $output .= "</tr>\n"; } } // end if else { echo "No results"; } ?> <table class="center" style="text-align:center" width="400px" border="1" cellpadding="5" cellspacing="5"> <tr> <td colspan="2"> <a href="#A">A</a> <a href="#B">B</a> <a href="#C">C</a> <a href="#D">D</a> <a href="#E">E</a> <a href="#F">F</a> <a href="#G">G</a> <a href="#H">H</a> <a href="#I">I</a> <a href="#J">J</a> <a href="#K">K</a> <a href="#L">L</a> <a href="#M">M</a> </td> </tr> <tr> <td colspan="2"> <a href="#N">N</a> <a href="#O">O</a> <a href="#P">P</a> <a href="#Q">Q</a> <a href="#R">R</a> <a href="#S">S</a> <a href="#T">T</a> <a href="#U">U</a> <a href="#V">V</a> <a href="#W">W</a> <a href="#X">X</a> <a href="#Y">Y</a> <a href="#Z">Z</a> </td> </tr> <?php echo $output; ?> </table>
  11. Wow, someone actual read that! I will try to test code if it doesn't mean I have to put a lot of work into it. If a database is involved I usually won't.
  12. Well, you could just as easily create the links at the top to only include the letters for which there are results! What you are asking is easy enough, but one possible issue is that the lists on each side might not be uniform. For example, if there are a lot of records in the A-M range, the left side of the list could be much longer than the list on the right. <?php $conn = mysql_connect('localhost','hidden', 'hidden') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('hidden', $conn) or trigger_error("SQL", E_USER_ERROR); //Query ALL the records ordered by make $query = "SELECT tblmake.make, tblmake.url, COUNT(tblmodel.modelid) AS model_count FROM tblmake LEFT JOIN tblmodel ON tblmake.makid = tblmodel.makeid GROUP BY tblmake.makid ORDER BY tblmake.make ASC"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); $total_records = mysql_num_rows($result); if($total_records > 0) { //There were results, let's display them $letters = array ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $row = mysql_fetch_assoc($result) foreach($letters as $letter) { $letter_idx = array_search($letter, $letters); $side = ($letter_idx < 13)?'left':'right'; $td[$side] .= "<br /><h1><a name=\"$letter\">$letter</a></h1>\n"; while (substr($row['make'], 0, 1) == $letter) { $td[$side] .= "<a href=\"{$row['url']}\">{$row['make']}</a> ({$row['model_count']})<br />\n"; if (!$row = mysql_fetch_assoc($result)) { break; } } } } // end if else { echo "No results"; } ?> <table class="center" style="text-align:center" width="400px" border="1" cellpadding="5" cellspacing="5"> <tr> <td colspan="2"> <a href="#A">A</a> <a href="#B">B</a> <a href="#C">C</a> <a href="#D">D</a> <a href="#E">E</a> <a href="#F">F</a> <a href="#G">G</a> <a href="#H">H</a> <a href="#I">I</a> <a href="#J">J</a> <a href="#K">K</a> <a href="#L">L</a> <a href="#M">M</a> </td> </tr> <tr> <td colspan="2"> <a href="#N">N</a> <a href="#O">O</a> <a href="#P">P</a> <a href="#Q">Q</a> <a href="#R">R</a> <a href="#S">S</a> <a href="#T">T</a> <a href="#U">U</a> <a href="#V">V</a> <a href="#W">W</a> <a href="#X">X</a> <a href="#Y">Y</a> <a href="#Z">Z</a> </td> </tr> <tr> <td valign="top"><?php echo $td['left']; ?></td> <td valign="top"><?php echo $td['right']; ?></td> </tr> </table>
  13. Um, not sure what you are asking for is what you really want. There will be many letters without any results. Do you want letters without results listed (e.g. 'Z')? And how do you want the letters displayed? Like this A B C D E f ... Or like this A N B O C P ... Edit: Also, post the code that you have working for any changes to be made.
  14. The query you posted above is not the one I posted for you in a different thread. There is no GROUP BY clause - which is probably the problem. <?php $conn = mysql_connect('localhost','deleted', 'deleted') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('databasename', $conn) or trigger_error("SQL", E_USER_ERROR); //Query ALL the records ordered by make $query = "SELECT tblmake.make, tblmake.url, COUNT(tblmodel.modelid) AS model_count FROM tblmake LEFT JOIN models ON tblmake.makeid = tblmodel.makeid GROUP BY tblmodel.modelid ORDER BY tblmake.make ASC"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); if(mysql_num_rows($result) >= 1) { //There were results, let's display them $current_letter = false; while($row = mysql_fetch_assoc($result)) { //Detected a new letter. Insert header anchor if($current_letter != substr($row['make'], 0, 1)) { $current_letter = substr($row['make'], 0, 1); echo "<br /><h1><a name=\"$current_letter\">$current_letter</a></h1><br />"; } //Display the current make with count echo "<a href=\"{$row['url']}\">{$row['make']} ({$row['model_count']})</a><br />"; } // end while } // end if else { echo "None"; } ?>
  15. You apparently are only posting part of the code from your page, because that code only has 38 lines and the error is occuring on line 126. When you have a line number to work with it is much easier to find the problem. In this case though, I was able to spot the problem (as well as another one): In this section, I 1) forgot to change the "!=" to just "=" in the line after the IF condition and 2) forgot to include a semi-colon at the end of the same line //Detected a new letter. Insert header anchor if($current_letter != substr($row['make'], 0, 1)) { $current_letter = substr($row['make'], 0, 1); echo "<br /><h1><a name=\"$current_letter\">$current_letter</a></h1><br />"; } NOTE: I only post my code as a guide on a methodology that should work. I typically do not test it - especially when it involves a database that I do not have access to and do not want to try and replicate. I figure syntax errors should be easily solved by the person receiving the code.
  16. Some code showing your current structure would have been helpful <html> <head> <script type="text/javascript"> function changeImages(imgName, imageSrc) { var imageList = document.images; for (var imgIdx=0; imgIdx<imageList.length; imgIdx++) { if(imageList[imgIdx].name==imgName) { imageList[imgIdx].src = imageSrc; } } return; } </script> </head> <body> <img name="test1" src="image1.jpg"> <img name="test1" src="image1.jpg"><br><br> <img name="test2" src="image2.jpg"> <img name="test2" src="image2.jpg"><br><br> <button onclick="changeImages('test1', 'image1.jpg');">Change Test 1 to Image 1</button> <button onclick="changeImages('test1', 'image2.jpg');">Change Test 1 to Image 2</button> <button onclick="changeImages('test2', 'image1.jpg');">Change Test 2 to Image 1</button> <button onclick="changeImages('test2', 'image2.jpg');">Change Test 2 to Image 2</button> </body> </html>
  17. <html> <head> <script type="text/javascript"> function togglesec(radioOption) { var radioGroup = radioOption.parentNode.childNodes; for(var opt=0; opt<radioGroup.length; opt++) { if (radioGroup[opt].type=='radio') { var divObj = document.getElementById(radioGroup[opt].value); divObj.style.display = (radioGroup[opt].checked) ? 'block':'none'; } } return; } </script> </head> <body> <form> <div id="sections" style="float: left; width: 100px;"> <input type="radio" name="togglesecs" value="buildings" onclick="togglesec(this);" />Buildings<br> <input type="radio" name="togglesecs" value="units" onclick="togglesec(this);" />Units<br> <input type="radio" name="togglesecs" value="units1" onclick="togglesec(this);" />Units1<br> <input type="radio" name="togglesecs" value="units2" onclick="togglesec(this);" />Units2 </div> <div id="buildings" style="float: left; width: 150px; border-left: 1px gray dashed; display:none;"> <input type="radio" name="toggledivs" value="bldlvl1" onclick="togglesec(this);" />Level 1 buildings<br> <input type="radio" name="toggledivs" value="bldlvl2" onclick="togglesec(this);" />Level 2 buildings<br> <input type="radio" name="toggledivs" value="bldlvl3" onclick="togglesec(this);" />Level 3 buildings<br> <input type="radio" name="toggledivs" value="bldlvl4" onclick="togglesec(this);" />Level 4 buildings<br> <input type="radio" name="toggledivs" value="bldlvl5" onclick="togglesec(this);" />Level 5 buildings<br> <input type="radio" name="toggledivs" value="bldlvl6" onclick="togglesec(this);" />Level 6 buildings<br> <input type="radio" name="toggledivs" value="bldlvl7" onclick="togglesec(this);" />Level 7 buildings<br> <input type="radio" name="toggledivs" value="bldlvl8" onclick="togglesec(this);" />Level 8 buildings<br> <input type="radio" name="toggledivs" value="bldlvl9" onclick="togglesec(this);" />Level 9 buildings<br> <input type="radio" name="toggledivs" value="bldlvl10" onclick="togglesec(this);" />Level 10 buildings </div> <div id="units" style="float: left; width: 150px; border-left: 1px gray dashed; display:none;">Units</div> <div id="units1" style="float: left; width: 150px; border-left: 1px gray dashed; display:none;">Units1</div> <div id="units2" style="float: left; width: 150px; border-left: 1px gray dashed; display:none;">Units2</div> </form> </body> </html>
  18. No offense Permiso, but doing queries within loops is bad form in my opinion. It can lead to severe performance issues. Note: you will need to modify the table and field names in the JOIN part of the query as appropriate for your database. //Query ALL the records ordered by make $query = "SELECT tmake.make, tmake.url, COUNT(models.model) as model_count FROM tmake JOIN models ON models.makeid = tmake.makeid ORDER BY tmake.make GROUP BY models.model"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); if(mysql_num_rows($result) >= 1) { //There were results, let's display them $current_letter = false; while($row = mysql_fetch_assoc($result)) { //Detected a new letter. Insert header anchor if($current_letter != substr($row['make'], 0, 1)) { $current_letter != substr($row['make'], 0, 1) echo "<br /><h1><a name=\"$current_letter\">$current_letter</a></h1><br />"; } //Display the current make with count echo "<a href=\"{$row['url']}\">{$row['make']} ({$row['model_count']})</a><br />"; } // end while } // end if else { //There were no results echo "None"; }
  19. You will need to put the INPUT tags within FORM tags for this to work: <html> <head> <script type="text/javascript"> function togglesec(radioOption) { var radioGroup = radioOption.parentNode; for(var opt=0; opt<radioGroup.length; opt++) { var divObj = document.getElementById(radioGroup[opt].value); divObj.style.display = (radioGroup[opt].checked) ? 'block':'none'; } return; } </script> </head> <body> <form> <input type="radio" name="togglesecs" value="buildings" onclick="togglesec(this);" />Buildings<br> <input type="radio" name="togglesecs" value="units" onclick="togglesec(this);" />Units <div id="buildings" style="display:none;">test1</div> <div id="units" style="display:none;">test2</div> </form> </body> </html>
  20. It depends upon the process flow you are trying to achieve. I typically have my forms pages post to the same page that creates the form. That way I can validate the user's data and, if there are errors, easily redisplay the form with the input they had entered. In this situation, I don't have clue what the problem is. You don't show what is in the pubdelete.php file. Also, the snippet you posted above has the exact same problem I explained before. It would delete the record before the user ever had a chance to confirm.
  21. This should be posted as a new topic
  22. My pleasure. Please make topic as solved!
  23. You don't want to multiply the $tolimit variable. The two varialbes for limit are the start index and the count. Using that logic page 1 would return the first 10 records, page two would return the next 20 records, page three would return the next 30 records, etc. Leave the $tolimit at 10 (or whatever count you want displayed on a page. In fact, it would be better to use a variable to determine the number of records per page so you can change it easily with one value: $records_per_page = 10; $page = (int) $_GET['page']; //Convert to an int //Determine total pages available $query = "SELECT COUNT(*) FROM table"; $result = mysql_query($query); $record = mysql_fetch_row($result); $total_pages = ceil($record[0] / $records_per_page); if ($page < 1 || $page > $total_pages) { $page = 1 } $limit_offset = ($page * $records_per_page) - $records_per_page; $query = "SELECT * FROM table ORDER BY somefield LIMIT $offset, $records_per_page";
  24. I took the code you posted above and made a test page. Works fine in IE7. Must be something else that is causing the problem. <html> <head> <script type="text/javascript"> window.onload = function () { alert(document.getElementById('showcase1').innerHTML); } </script> </head> <body> <table><tr> <td align="center" valign="middle" id="showcase1" style="width:150px;height:150px;"><img src="collection_lib/spacer.gif" id="showcase1_img" alt="" width="150" height="150" border="0" /></td> </tr></table> </body> </html>
  25. To get the results to populate the date/times in the proper order add the date to the ORDER clause in the query: $query="SELECT movies.id, movies.name, movies.age_limit, movies.length_time, movies.filmweb, movies.picture, date.id AS date_id, date, time.id AS time_id, time FROM movies JOIN date ON movies.id = date.movie_id JOIN time ON date.id = time.date_id ORDER BY movies.name, date"; For the date issue, I left off a couple lines. Replace the WHILE loop with this code while($movie = mysql_fetch_assoc($result)) { //Check for new movie if ($current_film_name != $movie['name']) { //New movie if($current_film_name != "") { //If not the first record, display the last movie displayMovie($m_name, $m_image, $m_age_limit, $m_length, $m_web, $m_dates, $m_times); } $current_film_name = $movie['name']; $m_name = $movie['name']; $m_image = $movie['picture']; $m_age_limit = $movie['age_limit']; $m_length = $movie['length_time']; $m_web = $movie['filmweb']; $m_dates = ""; $m_times = ""; $current_film_date = ""; } //Date/time data if ($current_film_date != $movie['date']) { //Different date from last record, show it $current_film_date = $movie['date']; $m_dates .= "{$movie['date']}<br>"; } else { //Same date as last, line break $m_dates .= "<br>"; } //Time date $m_times .= "{$movie['time']}<br>"; } That should take care of it
×
×
  • 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.