Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. Ok, I've made a lot of changes. You should really give variables descriptive names - not group1, group2, etc. I used 'goal', 'level' and 'days'. I also changed the values to values you can use directly in the code without a lot of IF/ELSE statements. I noticed that all of the queries were using a table with 'beg' in the name and there were no intermediate tables (I assumed that was a mistake and that there are tables with 'int' in the name). Although, I rewrote the code using mutiple tables as you had in the original code, I will state that that is a terrible idea. Simply create one table with additional fields for goal, level & days. You can then query that one table using those fields as criteria. Using multiple tables is very poor design in this case. Note: I did not test any of this, so there are probably some syntax errors New Form <form action="weightloss_beg_3day_exercise.php" method="POST"> <font color="#D3D3D3" size="2" face="Verdana"><b>What is your goal?</b></font> <table border="1" width="55%" height="70%" cellspacing="1" cellpadding="1"> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>Weight Loss:</b></font></td> <td border="1" width="30%" height="20%" cellspacing="1" cellpadding="1"><input type="radio" name="goal" value="weightloss" CHECKED></td> </tr> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>Tone:</b></font></td> <td><input type="radio" name="goal" value="tone"></td> </tr> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>Muscle Building:</b></font></td> <td><input type="radio" name="goal" value="musclebuilding"></td> </tr> </table><br><br> <font color="#D3D3D3" size="2" face="Verdana"><b>Are you a/an?</b></font> <table border="1" width="55%" height="70%" cellspacing="1" cellpadding="1"> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>Beginner:</b></font></td> <td border="1" width="30%" height="20%" cellspacing="1" cellpadding="1"><input type="radio" name="level" value="beg" CHECKED></td> </tr> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>Intermediate:</b></font></td> <td><input type="radio" name="level" value="int"></td> </tr> </table><br><br> <font color="#D3D3D3" size="2" face="Verdana"><b>How many days can you train per week?</b></font> <table border="1" width="55%" height="70%" cellspacing="1" cellpadding="1"> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>3 Days:</b></font></td> <td border="1" width="30%" height="20%" cellspacing="1" cellpadding="1"><input type="radio" name="days" value="3" CHECKED></td> </tr> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>4 Days:</b></font></td> <td><input type="radio" name="days" value="4"></td> </tr> <tr> <td><font color="#D3D3D3" size="2" face="Verdana"><b>5 Days:</b></font></td> <td><input type="radio" name="days" value="5"></td> </tr> <tr> <td align="center"><input type="submit" name="Submitcreateworkout" value="Get Program"></td> </tr> </table> </form> New PHP <?php if (isset($_POST['Submitcreateworkout'])) { $query = "SELECT * FROM {$goal}_{$level}_{$days}day_exercise"; $result = mysql_query($query) or die (mysql_error()); $day = 1; while ($row = mysql_fetch_array($sql_result)) { echo "<b>Your weightloss program for day {$day} is:</b><br><br>"; echo "<table width =\"50%\ align =\"center\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"font-size: 70%\">\n"; echo " <tr>\n"; echo " <td width =\"5%\ height =\"5%\ border=\"1\" cellpadding=\"1\" cellspacing=\"1\">\n"; echo " <a href=\"{$row['link']}.php\">{$row['name']}</a>"; #echo " <a href=\"popup(".$row['link'].".php)\">".$row['name']."</a>"; #echo " <A HREF=\".$row['link']." onClick=\"return popup(".$row['link'].".php)"\>".$row['name']."</A>"; echo " </td>\n"; echo " <td width =\"5%\ height =\"5%\ border=\"1\" cellpadding=\"1\" cellspacing=\"1\">{$row['sets']}</td>\n"; echo " <td width =\"5%\ height =\"5%\ border=\"1\" cellpadding=\"1\" cellspacing=\"1\">{$row['reps']}</td>\n"; echo " <td width =\"5%\ height =\"5%\ border=\"1\" cellpadding=\"1\" cellspacing=\"1\">{$row['duration']}</td>\n" echo " </tr>"; echo "</table><br>\n"; } } ?> Wow, look how much smaller that is. If you were to go with one table, as I think you really should, the query would look something like this: $query = "SELECT * FROM programs WHERE goal='$goal' AND level='$level' AND days='$days'"; Much, much easier to maintain.
  2. 1. Use code tags when positing code. makes it MUCH easier to read. 2. Are you kidding me with all those if/else's 3. All of your IF statemetns are if (isset($_POST['Submitcreateworkout'])) { The submit button is the field named 'Submitcreateworkout', so that IF will always return true and only the first one will run since all of the others are ELSE clauses. I'll take a stab at correcting the code.
  3. Or, Create those "files" as javascript and then simply include them using a javascript SRC attribute. Besides, AJAX requires server-side code and you already stated you are only using client-side code. Example: main.htm <html> <head> <script type="text/javascript"> window.onload = function() { document.getElementById('events').innerHTML = eventsHTML; } </script> <script src="events.inc.js"></script> </head> <body> Here are today's events: <div id="events"></div> </body> </html> events.inc.js //Create the events html code as a variable //var eventsHTML; var eventsHTML = ''; eventsHTML += '<ul>'; eventsHTML += '<li>Underwater basket weaving</li>'; eventsHTML += '<li>Naked decathalon</li>'; eventsHTML += '<li>Hula Hoop Football</li>'; eventsHTML += '</ul>'; Resulting page will show ================== Here are today's events: Underwater basket weaving Naked decathalon Hula Hoop Football Of course, using javascript for something like this (including AJAX) is a poor solution. This really should be implemented server-side. But, you can also check if your server supports Server Side Includes (SSI) which will allow you to include an HTML file inside another HTML file.
  4. Probably needed to set it to true: selObj.options.setAttribute("selected", true); Please mark topic as solved.
  5. A simple modification will take care of that <?php $query="SELECT `Skill_Name`, `Weight` FROM ID_Table JOIN Job_ID ON ID_Table.Job_ID = Job_ID.Job_ID WHERE Job_ID.Job_Name ='{$_SESSION[Job_Name]}'"; $result = mysql_query($query) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result)) { $tblRows .= "<tr>"; $tblRows .= "<td>{$row['Skill_Name']}</td>"; $tblRows .= "<td>{$row['Weight']}</td>"; $tblRows .= "</tr>\n"; } echo "<table width=\"200\" border=\"1\">\n"; echo "<tr><th>Skill<th><th>Weight</th></tr>\n"; echo $tblRows; echo "<table>\n"; ?>
  6. Here's a working example. No matter what the user does, all the items in the select list are inluded in the post data: <?php if (isset($_POST['test'])) { $response = "The following values were submitted:"; $response .= "<ul>\n"; foreach ($_POST['test'] as $value) { $response .= "<li>$value</li>\n"; } $response .= "</ul>\n"; } ?> <html> <head> <script type="text/javascript"> function selectAll(selectID) { selObj = document.getElementById(selectID); for(var i=0; i<selObj.options.length; i++) { selObj.options[i].selected = true; } return true; } </script> </head> <body> <?php echo $response; ?> <form method="POST" onsubmit="return selectAll('test');"> <select name="test[]" id="test" multiple="multiple" size="8"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> <option value="5">Five</option> </select> <br /> <button type="submit">Submit</button> </form> </body> </html>
  7. The solution I provided will do what you are asking. Run the function onsubmit() of the form for Select List B and all of the values in that list will be selected (before the form is submited) and be made part of the POST data. Either you are not understanding the solution or your explanation of what you want is not clear. In the example I posted above, if that function was run onsubmit() of the form, then every time that form is submitted, the variable $_POST['test'] will always be an array of the values (1,2,3,4,5) no matter if the user selected any options in that list or not.
  8. First off, you are reinventing the wheel with some of your code. This $sep = ''; $sid_list = ''; foreach ($Skill_Name as $sid) { $sid_list .= "$sep$sid"; $sep = ','; } $sid_list .= ''; Could be done with just this $sid_list = implode(',', $Skill_Name); Also, your queries aren't making sense to me. The first query gets a singe JOB_ID (or if it get's multiple you are left with only one assigned to the $Job_ID1 valiable). Then int he second query you do a subquery in the WHERE clause for this Job_ID IN (SELECT Job_ID FROM Job_ID WHERE Job_ID=$Job_ID1) But, you are just creating a more complex way of testing if the value is equal to another SINGLE value. Besides you can get the restults you want with a single query (if I am reading that code right) Try this: $query="SELECT `Skill_Name`, `Weight` FROM ID_Table JOIN Job_ID ON ID_Table.Job_ID = Job_ID.Job_ID WHERE Job_ID.Job_Name ='{$_SESSION[Job_Name]}'"; $result = mysql_query($query) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result)) { $skillTbl .= "<tr><td>{$row['Skill_Name']}</td></tr>\n"; $WeightTbl .= "<tr><td>{$row['Weight']}</td></tr>\n"; } echo "SKILLS:<br>\n" echo "<table>\n{$skillTbl}<table>\n"; echo "WEIGHTS:<br>\n"; echo "<table>\n{$WeightTbl}<table>\n";
  9. The function below will select all the options in a select list. Just run it onsubmit() of the form. <html> <head> <script type="text/javascript"> function selectAll(selectID) { selObj = document.getElementById(selectID); for(var i=0; i<selObj.options.length; i++) { selObj.options[i].selected = true; } } </script> </head> <body> <select name="test" id="test" multiple="multiple" size="8"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> <option value="5">Five</option> </select> <br /> <button onclick="selectAll('test');">Select All</button> </body> </html>
  10. Works fine for me in IE7. Perhaps there is some other problem such as misformatted HTML, that is causing the problem Tested with this: <html> <body> <div id="content"> <div id="content-gallow"> <img src="images/gallow.gif"> </div> <div id="content-words"> <p><span id="words" name="words"> </span> </div> </div> <button onclick="alert(document.getElementById('words').innerHTML);">Test</button> </body> </html>
  11. preg_match_all("|<span[^>]*>(.*)</span>|U", $text, $matches);
  12. Well, using fetch_assoc() and extract were only added to show ways to make the code more efficient/readable - they had nthing to do with the real solution. The real problem was that the original code was extracting the first record, then when the while() loop starts it would extract the next record (thus the first record was dropped) Here's the original code with comments to explain why the first record in the result set was not displayed <?php $fetch_mostrecentarticles = mysql_query('SELECT * FROM articles ORDER BY id DESC LIMIT 0,10'); //First record in result set is extracted and assigned to $display_mostrecentarticles $display_mostrecentarticles = mysql_fetch_array($fetch_mostrecentarticles); //Nothing is done with $display_mostrecentarticles before the while loop //The while loop STARTS by extracting the NEXT record from the result set. So, it will start //from the second record since the first one was already extracted above. The loop will then //continue through the remainder of the records in the result set. In other words, this loop will //only process records 2-10 (assuming there are 10 records in the result set). The solutin was //to remove the mysql_fetch_array() that comes before the WHILE loop. while ($display_mostrecentarticles = mysql_fetch_array($fetch_mostrecentarticles)) { echo '<li><a href="/articles/view.php?id='. $display_mostrecentarticles['id'] .'">' . $display_mostrecentarticles['date'] . '<br />' . $display_mostrecentarticles['title'] . '</a></li>'; } ?>
  13. The reason is simple. You extract the first record from the result set and don't use it. Then when you start the WHILE loop you are starting with the second record and continuing through the rest of the result set <?php $query = "SELECT id, date, title FROM articles ORDER BY id DESC LIMIT 0,10"; $result = mysql_query($query) or die(mysql_error()); while ($record = mysql_fetch_assoc($result)) { extract($record); echo "<li><a href=\"/articles/view.php?id={$id}\">{$date}<br />{$title}</a></li>\n"; } ?>
  14. First of all, the HTML is all out of wack! You're writing JS to the page before you have even opened the HTML tag. I've stripped out all the PHP in the code below - just use that format for generating the page <html> <head> <title>Page des poolers</title> <script type="text/javascript"> function formValidator(formObj) { if(!radioSelected(formObj['1vs8East'])) { alert("You must choose a team"); return false; } alert("Validation passes"); return true; } function radioSelected(radioGrp) { if (radioGrp.length) { //There are 2 or more options for (var i=0; i<radioGrp.length; i++) { if (radioGrp[i].checked) { return true; } } //No options were checked return false; } else { //There is only 1 option return radioGrp.checked; } } </script> </head> <body> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator(this)'> <b>Entrez vos choix pour la premiere ronde</b> <input type="submit" name="submit" value="Soumettre vos choix"> <br/> <fieldset> <legend> Est</legend> <label for="1vs8East_1"><input name="1vs8East" type="radio" id="1vs8East_1" value="Boston">Boston</label> <label for="1vs8East_2"><input name="1vs8East" type="radio" id="1vs8East_2" value="Buffalo">Buffalo</label> </fieldset> </form> </body> </html>
  15. Show 1) Your latest code, 2) What the current output looks like and 3) what you want the output to look like
  16. As I said "Not tested". Add a right paren at the end of the is_array test.
  17. Try this (not tested) <?php $xmlFiles = array(); function createXML($caption) { global $xmlObjects; $picT = $_POST['picT']; $photoT = $_POST['photoT']; $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gallery></gallery>"; $xmlobj = simplexml_load_string($xmltext); $nameCapsA = $xmlobj->addChild($picT); $nameCapsA->addAttribute("name", $photoT); $nameCapsA->addAttribute("caption", $caption); $xmlFiles[] = $xmlobj->asXML(); } if(isset($_POST['create_xml'])) { if (is_array($_POST['captionT']) { foreach ($_POST['captionT'] as $caption) { createXML($caption); } } else { createXML($_POST['captionT']); } } echo header("Content-type: text/plain"); //Echo data from each file. foreach ($xmlFiles as $xmlFile) { echo $xmlFile . "<br /><br />\n"; } ?>
  18. I don't think you can do what you are wanting. You can have a web page "open" a file (i.e. server the file to the user, without having a physical file) directly, but I've never seen a page open multiple files using that method, and I don't think you can. You could, however, have the script create physical file for the user and display a page for the user to download each file.
  19. Did you miss this part You definitely need that validation server-side in case the user has JS diabled. BUt, adding JS validation is definitely a nice feature. It would have been helpful if you posted just sample HTML code since this is a JS issue. Use this function function submitcheck(formObj) { //Only validate if there are fields to validate if (checkOptions = formObj.elements['pro[]']) { if(checkOptions.length) { //chekOptions is an array (i.e. two or more options) for(var i=0; i<checkOptions.length; i++) { if (checkOptions[i].checked) { return true; } } //No options were selected return false; } else { //chekOptions is not an array (i.e. only one option) return checkOptions.checked; } } //There were no options on the form return true; } Change the onsibmit function to this echo "<table border='1'><form id='field' action='downclus.php' method='post' onsubmit='return submitcheck(this)'>";
  20. I have no idea why you would want to save form field values to cookies. If you have a form I would expect that you are using some type of server-side code (such as PHP) to process the form. It is much more efficient to repopulate the form on the server-side (using POST variables) than in JavaScript. But you can allow the at symbol by simply adding it to the regex expression var myregexp = new RegExp(nameQuery + '([\\w@]*)');
  21. I will, and you are (I'm pretty sure). There are six different scenarios. Let's create some examples for illustration purposes. Let's assume a current registration period in the DB is Jan 3 to Jan 7. Here are examples of the six different scenarios. 1-1 to 1-2 (OK) Exist before current period 1-1 to 1-5 (Error) Overlaps the beginning of current 1-1 to 1-9 (Error) Completely overlaps the current 1-4 to 1-6 (Error) Completely within current 1-5 to 1-9 (Error) Overlaps the end of current 1-8 to 1-9 (OK) Exists after current period So, now let's apply the test of WHERE $new_start_date <= 'end_date' AND $new_end_date >= 'start_date' New new start <= new end >= Dates current end current start (1-7) (1-3) ========================================= 1-1 to 1-2 Yes No 1-1 to 1-5 Yes Yes 1-1 to 1-9 Yes Yes 1-4 to 1-6 Yes Yes 1-5 to 1-9 Yes Yes 1-8 to 1-9 No Yes As you can see the first and last scenarios are the only two where the result would be false. So the query I provided will find any current dates where there is a conflict. Let me know if you see any error in that logic.
  22. Ahh. When I started writing that code I was in the minset of the conflict could either be overlapping the beginning or ending of a current registration. As I wrapped my head around the clauses and started revising them I didn't realize I came up with the same thing which handles every eventuality. So, all that is needed is this $query = "SELECT * FROM reservations WHERE $new_start_date <= 'end_date' AND $new_end_date >= 'start_date'"; You are correct, but I'm not going to always add ALL the details not specific to the solution. For example, youwould also want to use mysql_real_escape_string() on the POST values as well. I leave it up to the OP to implement all the other necessities.
  23. Assuming this is in a database, it's quite simple: //Variables to be tesed $new_start_date = $_POST['new_start_date']; $new_end_date = $_POST['new_end_date']; $query = "SELECT * FROM reservations WHERE ($new_start_date <= 'end_date' AND $new_end_date >= 'start_date') OR ($new_start_date <= 'end_date' AND $new_end_date >= 'start_date')"; $result = mysql_query($query); if (mysql_num_rows($result)>0) { echo "There is a conflict"; } else { echo "No conflict"; }
  24. Oh, and if they would need to stay persistent for a user from session to sessin then, of course, you would use cookies. And, if you need to "save" any of these values you would want to use a database.
×
×
  • 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.