Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
You switch around the logic from what I provided. For example this is what I gave you //Check for new movie if ($current_film_name != $movie['name']) { $new_movie = true; //Logic to open the new movie table and display basic movie info } else { $new_movie = false; } //Logic to display the date/times for the individual records here is what you did //Check for new movie if ($current_film_name != $movie['name']) { $new_movie = true; //Logic to open the new movie table and display basic movie info //Logic to display the date/times for the individual records } else { $new_movie = false; } See the problem? Since all of the code for presenting the data (basic and date/time) has been moved into the true branch, that code is only run when a "new movie" is detected in the results (i.e. the first record for each movie)! The other records for each move are not processed at all. There is a problem with trying to use the current code with your new design in that the current code would create a new table row for each date/time record, but the image is set to be only three rows high. But, you won't know how many rows there will be. Your new design is better, so you will have to take a different approach - one which I think is better and more cleaner anyway. Try this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Vinstra Kino - Oversikt</title> <style type="text/css"> <!-- body { background-color: #000000; } .style1 {color: #FFFFFF} .style2 { color: #FFFFFF; font-size: 19px; } a:link { color: #FFFFFF; text-decoration: none; } a:visited { text-decoration: none; color: #FFFFFF; } a:hover { text-decoration: none; color: #B10202; } a:active { text-decoration: none; color: #AE0202; } --> </style> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <!--Start of the whole page table--> <table background="bilder/bakgrunn_oversikt.png" style="background-repeat:no-repeat" width="963" border="0" cellpadding="0" cellspacing="0"> <!--Logo and menu--> <tr> <td width="170" rowspan="2"" valign="bottom"left="left"><p class="style1"> </p> <p class="style2"><a href="index.html">Hjemmeside</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="oversikt.html">Billettbestilling/<br /> Kinoprogram</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="om.html">Om Vinstra Kino</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="kontakt.html">Kontakt oss</a></p> <hr size="1" color="#000000" /> <p class="style1"> </p></td> <td width="793" height="128" align="left" valign="top"> </td> </tr> <!--End logo and menu--> <!--Picture following the movies y-axis.--> <tr> <td background='bilder/bakgrunn_liten.png' style='background-repeat:repeat-y' align="left" valign="top"> <?php function displayMovie($name, $image, $age, $length, $web, $dates, $times) { echo " <table background='bilder/Vindu_oversikt.png' width='764' height='300' border="1" borderColor="blue" align='center' cellpadding='0' cellspacing='0'> <tr> <td height='29' colspan='7' valign='bottom'> $name </td> </tr> <tr> <td width='204' rowspan='3' align="right" valign='top'><img border='2px' src='$image' alt='$name' width='190' height='235' /></td> <td width='116' align='center' valign='top' bordercolor='#F0F0F0'><span class='style12'>Aldersgrense:</span></td> <td width='82' height='6' valign='top'><span class='style12'>Spilltid:</span></td> <td width='64' height='6' valign='top'><span class='style12'>Filmweb:</span></td> <td width='74' height='6' valign='top'><span class='style12'>Dato:</span></td> <td width='84' height='6' align='center' valign='top'><span class='style12'>Klokkeslett:</span></td> <td width='138' align='center' valign='top'>Ledige billetter:</td> </tr> <tr> <td height='160' align='center' valign='top'>$age år</td> <td valign='top'>$length</td> <td valign='top'><a href='$web'>Link</a></td> <td valign='top'>$dates</td> <td align='center' valign='top'>$times</td> <td align='center' valign='top'></td> </tr> <tr> <td height='90' align='center' colspan='6' valign='middle'><a href='bestill.html'><img src='../bestill.png' alt='bestill' width='70' height='21' border='0' /></a></td> </tr> </table>"; } require 'php/tilkobling.php'; $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"; $result=mysql_query($query); $current_film_name = ""; $current_film_date = ""; 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 = $movie['date']; $m_times = $movie['time']; } else { if ($current_film_date != $movie['date']) { //Different date from last record, show it $movie_dates .= "<br>{$movie['date']}"; } else { //Same date as last, line break $movie_dates .= "<br>"; } $movie_times .= "<br>{$movie['time']}"; } } //Display the last movie displayMovie($m_name, $m_image, $m_age_limit, $m_length, $m_web, $m_dates, $m_times); ?> </td> </tr> <!--End picture following the movies y-axis.--> <!--Buttom picture--> <tr> <td height="63" align="right" valign="top"> </td> <td valign="top"><img src="bilder/bonn.png" width="782" height="63" alt="bånn" /></td> </tr> <!--End buttom picture--> </table> <!--End on whole page.--> </body> </html>
-
I think that's a lot better. Although there are some errors. Here's a tip: whenever working with tables - especially nested ones, it's a good idea to create them with different color borders. you can then easily see if there are any problems with the table structure. Then just remove the borders when development is done. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Vinstra Kino - Oversikt</title> <style type="text/css"> <!-- body { background-color: #000000; } td { color: white; } .style1 {color: #FFFFFF} .style2 { color: #FFFFFF; font-size: 19px; } a:link { color: #FFFFFF; text-decoration: none; } a:visited { text-decoration: none; color: #FFFFFF; } a:hover { text-decoration: none; color: #B10202; } a:active { text-decoration: none; color: #AE0202; } --> </style> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <!--Start of the whole page table--> <table background="bilder/bakgrunn_oversikt.png" width="963" border="1" borderColor="white" cellpadding="0" cellspacing="0"> <!--Logo and menu--> <tr> <td width="170" rowspan="2"" valign="bottom"left="left"><p class="style1"> </p> <p class="style2"><a href="index.html">Hjemmeside</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="oversikt.html">Billettbestilling/<br /> Kinoprogram</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="om.html">Om Vinstra Kino</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="kontakt.html">Kontakt oss</a></p> <hr size="1" color="#000000" /> <p class="style1"> </p></td> <td width="793" height="128" align="left" valign="top"> </td> </tr> <!--End logo and menu--> <!--Picture following the movies y-axis.--> <tr> <td background='bilder/bakgrunn_liten.png' style='background-repeat:repeat-y' align="left" valign="top"> <!--The movie table--> <table background='bilder/Vindu_oversikt.png' width='764' height='300' border="1" borderColor="blue" align='center' cellpadding='0' cellspacing='0'> <tr> <td height='29' colspan='7' valign='bottom'> $film_navn </td> </tr> <tr> <td width='204' rowspan='3' align="right" valign='top'><img border='2px' src='$film_bilde' alt='$film_navn' width='190' height='235' /></td> <td width='116' align='center' valign='top' bordercolor='#F0F0F0'><span class='style12'>Aldersgrense:</span></td> <td width='82' height='6' valign='top'><span class='style12'>Spilltid:</span></td> <td width='64' height='6' valign='top'><span class='style12'>Filmweb:</span></td> <td width='74' height='6' valign='top'><span class='style12'>Dato:</span></td> <td width='84' height='6' align='center' valign='top'><span class='style12'>Klokkeslett:</span></td> <td width='138' align='center' valign='top'>Ledige billetter:</td> </tr> <tr> <td height='160' align='center' valign='top'>$film_aldersgrense år</td> <td valign='top'>$film_spilletid</td> <td valign='top'><a href='$film_filmweb'>Link</a></td> <td valign='top'>$film_dato</td> <td align='center' valign='top'>$film_tid</td> <td align='center' valign='top'></td> </tr> <tr> <td height='90' align='center' colspan='6' valign='middle'><a href='bestill.html'><img src='../bestill.png' alt='bestill' width='70' height='21' border='0' /></a></td> </tr> </table> <!--End movie table--> </td> </tr> <!--End picture following the movies y-axis.--> <!--Buttom picture--> <tr> <td height="63" align="right" valign="top"> </td> <td valign="top"><img src="bilder/bonn.png" width="782" height="63" alt="bånn" /></td> </tr> <!--End buttom picture--> </table> <!--End on whole page.--> </body> </html>
-
Go ahead and attach a database output and I'll see what I can do. Your first code will probably work without any noticable effect as long as you are dealing with a small number of users AND the database is small. The problems will arise as the database grows. I worked on a project once where we were creating reports from hundreds (thousands?) of records and the developer writing it did what you did in your first code. When running those reports the page would time out before the process could finish when processing lots of records. Even if it does work, it is inifinitely better, in my opinion, to learn to do things the right way. I would still suggest a complete restructuring of that page. Would make things a whole lot easier.
-
[SOLVED] Save expand/collapse preference to a cookie!
Psycho replied to adx's topic in Javascript Help
Ah, yes. I tried to write that against your code, but didn't have the content to test it properly. Here's a complete working page. Note that the items will default to be displayed and then will disappear when the JavaScript runs on load. Looks kind of funny, so you might want to have them default the display to 'none' and only display if appropriate <html> <head> <script type="text/javascript"> function toggleList(id, displayValue) { var obj = document.getElementById(id); if(!displayValue) { var displayValue = (obj.style.display!='none')?'none':'block'; } obj.style.display = displayValue; setCookie(id, displayValue, 30); //Set expiration in days return; } window.onload = function() { //Create a line for each object you need to set the toggle //value for on load of the page. Set the ID value accordingly toggleList('div1', getCookie('div1')); toggleList('div2', getCookie('div2')); toggleList('div3', getCookie('div3')); return; } function setCookie(name, value, expiredays) { if (expiredays==null) { expiredays=0; } var expireDate = new Date(); expireDate.setDate(expireDate.getDate()+expiredays); var cookieVal = name + '=' +escape(value) + ';expires=' + expireDate.toGMTString(); document.cookie = cookieVal; return; } function getCookie(searchName) { if (document.cookie.length>0) { var nameValuePair, cookieName, cookieValue var pairs = document.cookie.split(';'); for(var i=0; i<pairs.length; i++) { nameValuePair = pairs[i].split('='); cookieName = nameValuePair[0].replace(/^\s+|\s+$/g,''); cookieValue = nameValuePair[1].replace(/^\s+|\s+$/g,''); if(cookieName == searchName) { return cookieValue; } } } return false; } </script> </head> <body> <button onclick="toggleList('div1');">Taggle Div 1</button><br> <div id="div1">Content for div 1</div> <br><br> <button onclick="toggleList('div2');">Taggle Div 2</button><br> <div id="div2">Content for div 2</div> <br><br> <button onclick="toggleList('div3');">Taggle Div 3</button><br> <div id="div3">Content for div 3</div> <br><br> </body> </html> -
[SOLVED] Save expand/collapse preference to a cookie!
Psycho replied to adx's topic in Javascript Help
function toggleList(id) { var obj = document.getElementById(id); var displayValue = (obj.style.display!='block')?'block':'none'; obj.style.display = displayValue; setCookie(id, displayValue); return; } window.onload = function() { //Create a line for each object you need to set the toggle //value for on load of the page. Set the ID value accordingly toggleList('object_1_ID'); toggleList('object_2_ID'); toggleList('object_3_ID'); return; } function setCookie(name, value, expiredays) { if (expiredays==null) { expiredays=0; } var expireDate = new Date(); expireDate.setDate(expireDate.getDate()+expiredays); var cookieVal = name + '=' +escape(value) + ';expires=' + expireDate.toGMTString(); document.cookie = cookieVal; return; } function getCookie(c_name) { if (document.cookie.length>0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end==-1) { c_end = document.cookie.length; } return unescape(document.cookie.substring(c_start,c_end)); } } return false; } -
No offense, but your code is very disorganized which makes fixing it much harder than it should be - especially for someone who didn't write it (i.e. me). Ok, here is another attempt with plenty of comments. It is difficult trying to code this with all the nested tables and not being able to test it properly - but I think this should work (may be some minor typos) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Vinstra Kino - Oversikt</title> <style type="text/css"> <!-- body { background-color: #000000; } .style1 {color: #FFFFFF} .style2 { color: #FFFFFF; font-size: 19px; } a:link { color: #FFFFFF; text-decoration: none; } a:visited { text-decoration: none; color: #FFFFFF; } a:hover { text-decoration: none; color: #B10202; } a:active { text-decoration: none; color: #AE0202; } --> </style> <meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)"> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="1017" border="0" align="left" cellpadding="0" cellspacing="0" background="bilder/bakgrunn_oversikt.png" style="background-repeat:no-repeat"> <tr > <td width="1017" height="705" align="left" valign="top"><table width="943" height="101" border="0"> <tr> <td width="937" height="83"> </td> </tr> <tr></tr> </table> <table width="1002" height="444" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="170" height="440" align="left" valign="top"><p class="style1"> </p> <p class="style2"><a href="index.html">Hjemmeside</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="oversikt.html">Billettbestilling/<br /> Kinoprogram</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="om.html">Om Vinstra Kino</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="kontakt.html">Kontakt oss</a></p> <hr size="1" color="#000000" /> <p class="style1"> </p></td> <td width="832" align="left" valign="top"><table width="819" height="438" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td width="819" height="438" valign="top"> <table width="782" height="242" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="782" height="27" align="center" valign="bottom"></td> </tr> <tr> <td height="206" align="left" valign="top" background="bilder/bakgrunn_liten.png" style="background-repeat:repeat-y"> <?php require 'php/tilkobling.php'; $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"; $result=mysql_query($query); $current_film_name = ""; $current_film_date = ""; while($movie = mysql_fetch_assoc($result)) { //Check for new movie if ($current_film_name != $movie['name']) { $new_movie = true; $current_film_name = $movie['name']; //Movie Background echo "<table background='bilder/Vindu_oversikt.png' width='756' height='219' border='0' align='center'>\n"; echo " <tr>\n"; echo " <td width='750' height='290' align='left' valign='top'>\n"; //Movie Main Table echo " <table width='727' height='243' align='center' cellpadding='0' cellspacing='0'>\n"; echo " <tr><td height='7' colspan='2' valign='buttom' style='padding-top:15px;'>{$movie['name']}</td></tr>\n"; echo " <tr>\n"; echo " <td width='190' rowspan='2' valign='top'><img border='2px' src='{$movie['picture']}' alt='{$movie['name']}' width='190' height='235' /></td>\n"; echo " <td width='116' align='center' valign='top' bordercolor='#F0F0F0'>\n\n"; //Movie Data Header echo "<table border="1">\n"; //Remove border after debugging echo " <tr>\n"; echo " <th class='style12'>Aldersgrense:</td>\n"; echo " <th width='82' height='6' valign='top'><span class='style12'>Spilltid:</th>\n"; echo " <th width='66' height='6' valign='top'><span class='style12'>Filmweb:</th>\n"; echo " <th width='76' height='6' valign='top'><span class='style12'>Dato:</th>\n"; echo " <th width='87' height='6' align='center' valign='top'><span class='style12'>Klokkeslett:</th>\n"; echo " <th width='108' align='center' valign='top'>Ledige billetter:</th>\n"; echo " </tr>\n"; } else { $new_movie = false; //If not first movie close previous movie tables if ($current_film_name != "") { //Close movie data table echo "</table>\n"; //BESTILL Link echo" <tr>"; echo" <td height='21' align='center' valign='bottom'><a href='bestill.html'><img src='../bestill.png' alt='bestill' width='70' height='21' border='0' /></a></td>"; echo" </tr>\n"; //Close Movie Main Table echo" </table>\n"; //close Background Table echo" </td>\n"; echo" </tr>\n"; echo"</table>\n"; } } //Movie data echo " <tr>"; //Check for new movie if ($new_movie) { //Display basic movie info (first three columns) echo " <td align='center' valign='top'>{$movie['age_limit']} år</td>\n"; echo " <td valign='top'>{$movie['length_time']}</td>\n"; echo " <td valign='top'><a href='{$movie['filmweb']}'>Link</a></td>\n"; } else { //Same movie as last, Display blank cells for first three columns echo " <td colspan='3' valign='top'> </td>\n"; } //Movie date (only display if new date) if ($current_film_date != $movie['date'] || $new_movie) { $current_film_date = $movie['date']; echo " <td valign='top'>{$movie['date']}</td>\n"; } else { //Same date as last, display blank cell echo " <td valign='top'> </td>\n"; } //Display time echo" <td>{$movie['date']}</td>\n"; //Close movie data row echo" </tr>\n"; } //CLOSE FINAL MOVIE TABLES //Close movie data table echo "</table>\n"; //BESTILL Link echo" <tr>"; echo" <td height='21' align='center' valign='bottom'><a href='bestill.html'><img src='../bestill.png' alt='bestill' width='70' height='21' border='0' /></a></td>"; echo" </tr>\n"; //Close Movie Main Table echo" </table>\n"; //close Background Table echo" </td>\n"; echo" </tr>\n"; echo"</table>\n"; ?> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <table width="980" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="156" height="63" align="right" valign="top"> </td> <td width="814" valign="top"><img src="bilder/bonn.png" width="799" height="63" alt="bånn" /></td> </tr> </table> <p> </p> <hr size="1" color="#000000" /></td> </tr> </table> </body> </html>
-
To be honest, your original code made little sense. There is no reason to get the values for $pubchar and $idpubdelete just to populate them into hidden fields that aren't even used. Looking at the script I posted, I see another mistake. Since I can't test against your DB I make no promise that there won't be errors. I expect the person utilizing the code to be able to debug any small issues. The problem with the original logic was that the page was deleting the record BEFORE the user ever made a selection. $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql); echo "<b>You really want to delete $name?"; Why ask them if they want to delete AFTER you delete the record? The code you posted above seems to do the same thing. You are calling the page with parameters on the query string (i.e. $_GET). You do NOT want to delete the record using the GET parameters, because the user has not made a confirmation which will be received via POST. The first script also used variables which have not been declared on the page, so I'm wondering if there is code you left out (e.g. $name & $abbreviation). Here's another update of the above code with comments. <?php if (isset($_POST['idpub'])) { //User has made a decision on the deletion confirmation if($_POST['button1']=='Yes') { //User confirmed the deletion include('connections.php'); $idpub = mysql_real_escape_string($_POST['idpub']); $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql) or die(mysql_error()); mysql_free_result($result); echo "The record has been deleted." } else { //User selected NOT to delete. Redirect somewhere else echo "The record has NOT been deleted." } //Confirmation process complete exit(); } else if (isset($_GET['idpub'])) { //Record passed on the query string for deletion //NOTE: You will need to correct this code for the right field names $idpub = mysql_real_escape_string($_GET['idpub']); //Get the name and abbreviation for the form $sql = "SELECT name, abbreviation FOM publisher WHERE idpub=$idpub"; $result = mysql_query($sql) or die(mysql_error()); $record = mysql_fetch_assoc($result); $name = $record['name']; $abbreviation = $record['abbreviation']; } else { //No id passed on GET or POST - error handling echo "No record selected"; exit(); } ?> <html> <body> You really want to delete <?php echo $name; ?> <form action="../assets/snippets/nbscripts/pubdelete.php" method="post"> <table border="1" cellpadding="0" cellspacing="0" width="500"> <tr> <td> <p class="bodytext"> You have selected '<B><?php echo $abbreviation; ?></B>' for deletion. Do you want to continue with the delete action? </p> </td> </tr> <tr><td> </td></tr> <tr> <td> <input id="button1" type="submit" value="Yes" name="submit"> <input id="button2" type="submit" value="No" name="submit"> <input type="hidden" value="<?php echo $idpub; ?>" name="idpub"> </td> </tr> </table> </form> </body> </html>
-
Just use the methodology I incorporated in the code I posted above: Use a "flag" to track the current movie or the current date so you know when to display the movie,date from the currently processed record. Here's an example. Let's say this is the output for two movies: Movie | Date | Time Crash | 02-06-09 | 12:30 Crash | 02-06-09 | 03:15 Crash | 02-06-09 | 05:45 Crash | 02-10-09 | 02:20 Crash | 02-10-09 | 04:15 Shrek | 02-12-09 | 08:20 You want the output to look like this Crash | 02-06-09 | 12:30 03:15 05:45 02-10-09 | 02:20 04:15 Shrek | 02-12-09 | 08:20 The code to generate that could look something like this //Variables to track current move/date $current_movie = ""; $current_date = ""; echo "<table>\n"; while($movie=mysql_fetch_assoc($result)) { //Start the row echo "<tr>\n"; //See if this movie title is the same as the last record(s) //If no, display the new title, otherwise use blank if ($current_movie != $move['title']) { $new_movie = true; $current_movie = $move['title']; echo "<td>{$current_movie}</td>\n"; } else { $new_movie = false; echo "<td> </td>\n"; } //See if this movie date is the same as the last record(s) //If no, display the new date, otherwise use blank //Note: also utilize "$new_movie" in case it is a different // movie but same date as last record of last movie if ($current_date != $move['date'] || $new_movie) { $current_date = $move['date'] echo "<td>{$current_date}</td>\n"; } else { echo "<td> </td>\n"; } //Display the time echo "<td>{$movie['time']}</td>\n"; //Cloe the row echo "<tr>\n"; } echo "</table>\n";
-
No, an anchor tag only "loads" the url into the browser. The URL, and only the URL, are passed. But, when passing parameters through a URL you can reference them using the $_GET global variable. Also, your code is wrong, the $id needs to be within PHP tags as well: <a name="delete" href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $id; ?>">Delete</a> if (isset($_GET['id'])) { // etc.. }
-
Corrected a couple typos in the cod I posted above: <?php if (isset($_POST['idpub'])) { if($_POST['button1']=='Yes') { include('connections.php'); $idpub = mysql_real_escape_string($_POST['idpub']); $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql) or die(mysql_error()); mysql_free_result($result); } else { //User selected NOT to delete. Redirect somewhere else } } ?> <html> <body> You really want to delete <?php echo $name; ?> <form action="../assets/snippets/nbscripts/pubdelete.php" method="post"> <table border="1" cellpadding="0" cellspacing="0" width="500"> <tr> <td> <p class="bodytext"> You have selected '<B><?php echo $abbreviation; ?></B>' for deletion. Do you want to continue with the delete action? </p> </td> </tr> <tr><td> </td></tr> <tr> <td> <input id="button1" type="submit" value="Yes" name="submit"> <input id="button2" type="submit" value="No" name="submit"> <input type="hidden" value="<?php echo $idpub; ?>" name="idpub"> </td> </tr> </table> </form> </body> </html>
-
Looking at the code it appears that page is called after the item is selected for deletion. Then that page on first load will ask for confirmation (using a form that is posted) for the deletion and on second load will delete the file. The problem is that the very first part of the script gets the values from the $_GET variable (presumable where the item was selected for deletion) and then uses those to run the deletion. So, the deletion occurs even before the suer get a chance to give confirmtion. You need to check for the POST values from the form before runing the delete process. Try something more like this <?php if (isset($_POST['idpub'])) { if($_POST['button1']=='Yes') { include('connections.php'); $idpub = mysql_real_escape_string($_POST['idpub']); $sql = "DELETE FROM publisher WHERE idpub=$idpub"; $result = mysql_query($sql) or die(mysql_error()); mysql_free_result($result); } else { //User selected NOT to delete. Redirect somewhere else } } ?> <html> <body> You really want to delete <?php echo $name; ?> <form action="../assets/snippets/nbscripts/pubdelete.php" method="post"> <table border="1" cellpadding="0" cellspacing="0" width="500"> <tr> <td> <p class="bodytext"> You have selected '<B>".$abbreviation."</B> for deletion. Do you want to continue with the delete action? </p> </td> </tr> <tr><td> </td></tr> <tr> <td> <input id="button1" type="submit" value="Yes" name="submit"> <input id="button2" type="submit" value="No" name="submit"> <input type="hidden" value="$idpub" name="idpub"> </td> </tr> </table> </form> </body> </html>
-
You *can* you the three queries, but the whole point of using a relatinal database is to be able to be able to work with "related" data. As I stated, using looping queries is very inefficient. If this is for your personal site, then go ahead. But, if this is for a site that many users would access, the method you were using can put a severe performance drag on the server. I wrote all of that code off-the-cuff, I wasn't able to test any of it because I don't have your database to test against. I tool a look at the query again and I still think it should work to get ALL the data you are asking for. And, the code I posted should handle the proper displaying of that data, but again I was not able to test it properly. Trying to code within all those nested tables was difficult without having output to test against. The output from the query should look something like this Movie1, Date1-1, Time1-1-1 Movie1, Date1-1, Time1-1-2 Movie1, Date1-1, Time1-1-3 Movie1, Date1-2, Time1-2-1 Movie1, Date1-2, Time1-2-1 Movie2, Date2-1, Time2-1-1
-
Your code is very difficult to follow. You have a LOT of nested tables that are unnecessary which complicates this even more. I would highly suggest you rethink the layout of the page to make the programatical creation more elegant. Also, you have multiple queries that you are running within loops. That is very inefficient. You only need ONE query to get all of the data you need. I attempted to rewrite the code as you requested, but because of the complexity with the nested tables I can't ensure it will work 100% <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Vinstra Kino - Oversikt</title> <style type="text/css"> <!-- body { background-color: #000000; } .style1 {color: #FFFFFF} .style2 { color: #FFFFFF; font-size: 19px; } a:link { color: #FFFFFF; text-decoration: none; } a:visited { text-decoration: none; color: #FFFFFF; } a:hover { text-decoration: none; color: #B10202; } a:active { text-decoration: none; color: #AE0202; } --> </style> <meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)"> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="1017" border="0" align="left" cellpadding="0" cellspacing="0" background="bilder/bakgrunn_oversikt.png" style="background-repeat:no-repeat"> <tr> <td width="1017" height="705" align="left" valign="top"><table width="943" height="101" border="0"> </tr> <tr> <td width="937" height="83"> </td> </tr> </table> <table width="1002" height="444" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="170" height="440" align="left" valign="top"><p class="style1"> </p> <p class="style2"><a href="index.html">Hjemmeside</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="oversikt.html">Billettbestilling/<br />Kinoprogram</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="om.html">Om Vinstra Kino</a></p> <hr size="1" color="#000000" /> <p class="style2"><a href="kontakt.html">Kontakt oss</a></p> <hr size="1" color="#000000" /> <p class="style1"> </p> </td> <td width="832" align="left" valign="top"> <table width="819" height="438" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td width="819" height="438" valign="top"> <table width="782" height="242" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="782" height="27" align="center" valign="bottom"></td> </tr> <tr> <td height="206" align="left" valign="top" background="bilder/bakgrunn_liten.png" style="background-repeat:repeat-y"> <?php require 'php/tilkobling.php'; $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"; $result=mysql_query($query); while ($movie = mysql_fetch_assoc($result)) { if ($current_movie_id != $movie['id']) { $current_movie_id = $movie['id']; echo"<table background='bilder/Vindu_oversikt.png' width='756' height='219' border='0' align='center'>\n"; echo" <tr>\n"; echo" <td width='750' height='290' align='left' valign='top'>\n"; echo" <table width='727' height='243' align='center' cellpadding='0' cellspacing='0'>\n"; echo" <tr>\n"; echo" <td height='7' colspan='7' valign='top'> </td>\n"; echo" </tr>\n"; echo" <tr>\n"; echo" <td height='7' colspan='7' valign='buttom'> {$movie['name']}</td>\n"; echo" </tr>\n"; echo" <tr>\n"; echo" <td width='190' rowspan='3' valign='top'>"; echo" <img border='2px' src='{$movie['picture']}' alt='{$movie['name']}' width='190' height='235' />"; echo" </td>\n"; echo" <td rowspan='3'>\n"; echo" <table>\n"; echo" <tr>\n"; echo" <td width='116' align='center' valign='top' bordercolor='#F0F0F0'><span class='style12'>Aldersgrense:</td>\n"; echo" <td width='82' height='6' valign='top'><span class='style12'>Spilltid:</td>\n"; echo" <td width='66' height='6' valign='top'><span class='style12'>Filmweb:</td>\n"; echo" <td width='76' height='6' valign='top'><span class='style12'>Dato:</td>\n"; echo" <td width='87' height='6' valign='top' align='center'><span class='style12'>Klokkeslett:</td>\n"; echo" <td width='108' align='center' valign='top'>Ledige billetter:</td>\n"; echo" </tr>\n"; echo" <tr>\n"; echo" <td height='160' align='center' valign='top'>{$movie['age_limit']} år</td>\n"; echo" <td rowspan='' valign='top'>{$movie['length_time']}</td>\n"; echo" <td rowspan='' valign='top'><a href='{$movie['filmweb']}'>Link</a></td>\n"; } else { echo " <tr>\n"; echo " <td colspan='3'> </td>\n"; } if ($current_date_id != $movie['date_id']) { $current_date_id != $movie['date_id']; echo" <td rowspan='' valign='top'>{$movie['date']}</td>\n"; } else { echo" <td rowspan='' valign='top'> </td>\n"; } echo " <td rowspan='' align='center' valign='top'>{$movie['time']}</td>\n"; echo " <td rowspan='' align='center' valign='top'></td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td height='21' align='center' valign='bottom'><a href='bestill.html'><img src='../bestill.png' alt='bestill' width='70' height='21' border='0' /></a></td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </td>\n"; echo " </tr>\n"; echo "</table>\n"; } ?> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <table width="980" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="156" height="63" align="right" valign="top"> </td> <td width="814" valign="top"><img src="bilder/bonn.png" width="799" height="63" alt="bånn" /></td> </tr> </table> <p> </p> <hr size="1" color="#000000" /> </body> </html>
-
Time range function not working for times after 11pm
Psycho replied to mo's topic in PHP Coding Help
You're welcome. Please mark topic as solved. -
Time range function not working for times after 11pm
Psycho replied to mo's topic in PHP Coding Help
There is an easier solution. Just add one line to adjust the end time to the next day if the end time is less than the start time: function create_time_range($start, $end, $by='30 mins') { $start_time = strtotime($start); $end_time = strtotime($end); //MOVE $end_time to next day if less than $start_time if($end_time < $start_time) { $end_time+= 86400; } $current = time(); $add_time = strtotime('+'.$by, $current); $diff = $add_time-$current; $times = array(); while ($start_time < $end_time) { $times[] = $start_time; $start_time += $diff; } $times[] = $start_time; return $times; } -
if (is_array($errormessage)) { foreach ($errormessage as $error) { echo $error; } } Or, better yet - in my opinion - declare the array at the beginning $errormessage = array(); Then check the count of errors: if (count($errormessage) > 0) { foreach ($errormessage as $error) { echo $error; } } I think that "reads" better to a human.
-
EDIT: Mis-posted. Deleted.
-
It's been many years since I took a math class, but wouldn't this be as simple as using the Pythagorean theorem? a(squared) + b(squared) = c(squared) Where a is the difference in lattitude and b is the difference in longitude. Then just calculate c to determine the distance between the two points. You could incorporate that calculation in the query and sort by the result to determine the closest point. $ip_longitude & $ip_lattitude must be defined prior to running the query. The values should be self explanatory. SELECT city_id, city_name, SQRT(POW(ABS($ip_longitude - city_longitude) ,2) + POW(ABS($ip_lattitude - city_lattitude), 2)) AS distance FROM cities ORDER BY distance LIMIT 1 Not sure how the performance would be on this. Perhaps the other methods above would be much faster.
-
When requesting help for JavaScript do not include PHP code. Post the HTML from the processed code - makes it much easier. There's nothing wrong with your javascript, except that you have several spaces in the middle of the action. But, your code is very disorganized. I see a lot of possible errors also. For example you use extract() on the record, but then use $row['client_id'] to get the value - why use extract then? Your process for creating the options list is not populating a value for the options so the javascript can't populate a value that does not exist. Try something like this <?php //Get current client id $query = "SELECT * FROM client "; $result = mysql_query($query)or die(mysql_error()); $record = mysql_fetch_assoc($result)); $client_id = $record['client_id']; //Create option list of clients $options = "<option value=\"\">Select</option>"; $query = "SELECT * FROM client "; $result = mysql_query($query)or die(mysql_error()); while ($record = mysql_fetch_assoc($result)) { $selected = ($record['id']==$client_id) ? ' selected="selected"' : ''; $options .= "<option value=\"{$record['id']}\"{$selected}>{$record['name']}</option>\n"; } ?> <tr> <td>Client ID : </td> <td><input type="text" id="cl_id" name="cl_id" value="<?php echo $client_id; ?>" size="3" disabled /></td> </tr> <tr> <td>Company Name : </td> <td> <select name="clientName" class="text" onchange="document.getElementById('cl_id').value=this.options[this.selectedIndex].value;"> <?php echo $options; ?> </select> </td> </tr>
-
The problem is in the second IF statement where the code is SETTING the value instead of TESTING the value. Need to use a double equal sign. function togspan(c_img) { if(document[c_img].src.indexOf("images/minus.gif")!= -1) { document[c_img].src="images/plus.gif"; document.getElementById('notes').style.display="none"; } else { document[c_img].src="images/minus.gif"; document.getElementById('notes').style.display="block"; } }
-
[SOLVED] How do I check if a directory is empty?
Psycho replied to lpxxfaintxx's topic in PHP Coding Help
I'd suggest using glob() instead of scandir(). Then you can return all the image files and nothing else from the directory without a loop. And if the results are empty - then there are no images. Give this a try $images = glob('{*.jpg,*.gif,*.png}', GLOB_BRACE); -
Assuming you have your start and end dates as data objects, I have a function that will give you the difference in days, hours, minutes, etc: //****************************************************************// // FUNCTION: dateDiff(Date1Obj, Date2Obj, [units], [precision]) // // // // Returns the difference between two date objects in the units // // specified (optional, default is days). The optional precision // // parameter determines the number of decimal places the result // // will be rounded to. Note: When the 'days' units is used the // // precision is not applicable (will determine the difference in // // calendar days). // // // // The units parameter can include the following: d=days, // // h = hours, m = minutes, s = seconds, ms = milliseconds // //****************************************************************// function dateDiff(date1Obj, date2Obj, units, precision) { //set the default untis var units = (units)?units:'d'; var precision = (precision && units!='d')?Math.pow(10, precision):1; //Calculate the units divisor switch (units) { case 'ms': //Milliseconds var units = 1; break; case 's': //Seconds var units = 1000; break; case 'm': //Minutes var units = 1000 * 60; break; case 'h': //hours var units = 1000 * 60 * 60; break; case 'd': //Calendar Days var units = 1000 * 60 * 60 * 24; //Normalize time to 12:00am to count calendar days date1Obj.setHours(0); // = new Date(Date1Obj.getFullYear(), Date1Obj.getMonth(), Date1Obj.getDate()); date2Obj.setHours(0); // = new Date(Date2Obj.getFullYear(), Date2Obj.getMonth(), Date2Obj.getDate()); break; } If you have hours in a decimal format, it would be fairly simple to reformat in an hh:mm format: function decToHours (hoursInDec) { var minsInt = Math.round(hoursInDec * 60); var hours = Math.round(minsInt/60); var mins = (minsInt - (hours * 60)); mins = (mins<10) ? '0'+mins : mins; return (hours+':'+mins); }
-
A trick I have always used is to save the js file with a .php, .asp, or whatever server-side interpreted extensions you are using. In my experience, this has always forced the browser to always get a current copy of the file.
-
I would really suggest making a function for this instead of putting the JS inline. Anyway, you have multiple problems: 1. A SPAN does not have a value. You need to use innerHTML to get the current value 2. You need to "cast" the value as a number so it doesn't get interpreted as text. Use parseFloat(). Try this onClick="document.getElementById('total').innerHTML = (parseFloat(document.getElementById('total').innerHTML) + 6);"
-
After rereading your initial post I will say that you need to be very careful with how you implement this because you are dealing with monetary calculations. Do NOT rely upon JavaScript for this. It's fine to use it for user experience, but you will want to recalculate the values on the server-side as well. Otherwise, a user w/o JavaScript enabled might go through without paying the calculated costs. Anyway, here is one way to accomplis what you are asking. If the cost was a fixed price based upon the destination, you could just put that price as the value for the options. But, it appears that there will be different types of calculations for each destination, so I went with this method (you would wnt to add additional validations and error handling: <html> <head> <script type="text/javascript"> window.onload = function() { //Set the onchange event and run it onload document.getElementById('destination').onchange = unpdateExportCost; unpdateExportCost(document.getElementById('destination')); } function unpdateExportCost(selObj) { if (!selObj) { selObj = this; } var selValue = selObj.options[selObj.selectedIndex].value.toUpperCase(); var cartTotal = (document.getElementById('cart_total').value); var exportCost = 0; switch(selValue) { case 'UK': exportCost = 0; break; case 'FR': exportCost = (.15 * cartTotal); break; case 'GE': exportCost = (.08 * cartTotal); break; case 'US': exportCost = (.11 * cartTotal) + 10; break; } document.getElementById('export_cost').value = exportCost.toFixed(2); return; } </script> </head> <body> <form name="cart" action="" method="POST"> Purchase price: <input type="text" name="cart_total" id="cart_total" value="95.35" /><br> Ships to: <select name="destination" onchange=""> <option value="UK">UK</option> <option value="FR">France</option> <option value="GE">Germany</option> <option value="US">United Stated</option> </select><br> Export Cost: <input type="text" name="export_cost" id="export_cost" readonly="readonly" /> </forM> </body>