Jump to content

TeamCIT

Members
  • Posts

    52
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

TeamCIT's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Alright everything is working as desired now. Thank you very much for your help!
  2. I tried this, and $counter is staying equal to 1 every time the submit button is pressed. I'm not too sure how to go about fixing this because I have never used a hidden field in a form before. Do you have any ideas why it would not be incrementing? Here is my code: $counter = isset($_POST['counter']) ? $_POST['counter'] : 0; if($_POST['submitted'] == true) { $counter++; $destChose = $_POST['destList']; $memChose = $_POST['memList']; $restChose = $_POST['restList']; //Destination If Statement if($destChose >= 1) { mysql_query("update combineddests set selected={$counter} where id={$destChose}"); }//closes if destchose //Memorial If Statement if($memChose >= 1) { mysql_query("update combineddests set selected={$counter} where id={$memChose}"); }//closes if memchose //Restaurant If Statement if($restChose >= 1) { mysql_query("update combineddests set selected={$counter} where id={$restChose}"); }//closes if restchose $result = mysql_query("SELECT place_name, place_addr FROM combineddests WHERE selected >= '1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["place_name"]; echo "</li>"; echo $mainCounter; }//closes while echo "<br />"; echo "<br />"; echo "Please select a destination."; }//closes main If submit //Code for Reset Button if($_POST['reset'] == true) { //resets selected places mysql_query("update combineddests set selected=0 where selected >='1'"); } //Code to generate Link if($_POST['linkgen'] == true) { //gets destination stuff into address $placeResult = mysql_query("SELECT place_addr FROM combineddests WHERE selected = '1'"); $placeCounter = 1; echo '<a href="http://maps.google.com/maps?f=d&source=s_d'; while ($placeRow = mysql_fetch_assoc($placeResult)) { switch($placeCounter) { case 1: echo "&saddr="; break; case 2: echo "&daddr="; break; default: echo "+to:"; break; } echo $placeRow['place_addr']; $placeCounter++; } echo "&pw=2"; echo "\">" . "Directions" . "</a>"; } ?> <html> <head> <title>Create a Tour</title> </head> <body> <br /> <br /> <form name="tourCreation" action="CombinedDB_CreateATour1.php" method="post"> Please complete this form to create your tour: <br /> <br /> Hot Spots:<br /> <select name="destList" size="10"> <option value="1">National Gallery of Art</option> <option value="2">National Archives & Records Administration</option> <option value="3">National Law Enforcement Officers Memorial</option> <option value="4">Kenilworth Aquatic Gardens</option> <option value="5">White House Park</option> <option value="6">Washington Photo Safari</option> <option value="7">Federal Bureau of Investigation</option> <option value="8">Franciscan Monastery - Commissariat of the Holy Land in America</option> <option value="9">National Portrait Gallery Special Events Department</option> <option value="10">Rock Creek Park</option> <option value="11">Anacostia Community Museum</option> <option value="12">National Shrine of the Immaculate Conception </option> <option value="13">U.S. National Arboretum</option> <option value="14">Union Station</option> </select> <br /> <br /> <br /> Memorials:<br /> <select name="memList" size="10"> <option value="18">Thomas Jefferson Memorial</option> <option value="19">Korean War Veterans Memorial</option> <option value="20">National World War II Memorial</option> <option value="21">African American Civil War Memorial</option> <option value="22">Franklin Delano Roosevelt Memorial</option> <option value="23">Marine Corps War Memorial</option> <option value="24">Women in Military Service for America Memorial</option> <option value="25">Air Force Memorial</option> <option value="26">Pentagon Memorial</option> <option value="27">Martin Luther King, Jr. National Memorial</option> </select> <br /> <br /> <br /> Restaurants:<br /> <select name="restList" size="10"> <option value="28">Old Ebbitt Grill</option> <option value="29">Song Que</option> <option value="30">Komi</option> <option value="31">Citronelle</option> <option value="32">Café Atlantico</option> <option value="33">CityZen</option> <option value="34">Palena Café</option> <option value="35">Vidalia</option> <option value="36">The Oval Room</option> <option value="37">The Source</option> <option value="38">BLT Steak</option> <option value="39">Kinkead’s</option> <option value="40">Teatro Goldoni</option> <option value="41">Mio</option> <option value="42">Cafe Du Parc</option> <option value="43">Tosca</option> </select> <input type="hidden" name="counter" value="<?php print $_POST['counter']; ?>" /> <br /> <br /> <br /> <input type="submit" name="submitted" value="Select Destination" /> <input type="submit" name="reset" value="Reset" /> <input type="submit" name="linkgen" value="Get Link" /> </form> <br /> <br /> </body> </html>
  3. Ok thank you this looks like it will be a lot easier to understand. How would I reference "$_POST['counter']"? Would it be "$counter" or do I assign a value to it here like this? if($_POST['submitted'] == true) { $counter = $_POST['counter']; $destChose = $_POST['destList']; $memChose = $_POST['memList']; $restChose = $_POST['restList']; $_POST['counter']++;
  4. Oh, ok. So does this make it so that I don't need to add "session_destroy();"? Also where would I put the unset($_SESSION['counter']); to make sure it doesn't reset the counter when the submit button is pressed? Should I open a new PHP tag at the bottom of my code, under my form? Or could I put it in the PHP tag at the top of my code before the HTML tags and have it not reset when the button is pressed? Would you not recommend using them solely on the fact that they are slow? Speed is not really an issue in my case, I just need it to generate a list in order using a database.
  5. How would I destroy the session value? Would I put session_destroy(); at the end of my PHP code, before my form? Will this cause the session to be destroyed when the submit button is pressed?
  6. This definitely looks like it could work. Could you help me out a little by explaining this code in minor detail to me? I'm still somewhat new to PHP and MySQL. Does the $_SESSION['counter'] piece create a counter that will not re-initialize each time the submit button is pressed? Also, what exactly is the question mark there for, and what does the "0 : " do? $_SESSION['counter'] = (!$_SESSION['counter']) ? 0 : $_SESSION['counter'];
  7. Hey guys, I'm trying to look for a way to create a variable that increments every time a submit button is pressed. What I have is a basic web page with a form that contains 3 drop-down lists. The user is to click an item in the list, then click the submit button at the bottom of the page to add it to a list. This list is created by a "selected" column in my database, that represents a numeric value. I have been using a MySQL query to update the "selected" column (starts as default "0") to a "1" if the item was selected, then another MySQL query to pull all the items in the database with a "1". What I would like to do instead is create a counter variable that updates the "selected" column in the database to an incrementing varaible instead so that I may list the items in the order chosen by the user, not in the order they appear in my database. tl;dr - I would like to update a column in my database with a counter variable that increases each time my submit button is pressed Here is the part of my code that is not working as desired, if this will help: $mainCounter = $mainCounter + $subCounter; if($_POST['submitted'] == true) { $subCounter++; $destChose = $_POST['destList']; $memChose = $_POST['memList']; $restChose = $_POST['restList']; //Destination If Statement if($destChose >= 1) { mysql_query("update combineddests set selected={$mainCounter} where id={$destChose}"); }//closes if destchose //Memorial If Statement if($memChose >= 1) { mysql_query("update combineddests set selected={$mainCounter} where id={$memChose}"); }//closes if memchose //Restaurant If Statement if($restChose >= 1) { mysql_query("update combineddests set selected={$mainCounter} where id={$restChose}"); }//closes if restchose $result = mysql_query("SELECT place_name, place_addr FROM combineddests WHERE selected >= '1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["place_name"]; echo "</li>"; echo $mainCounter; }//closes while echo "<br />"; echo "<br />"; echo "Please select a destination."; }//closes main If submit Any input / tips are greatly appreciated, thanks in advance!
  8. Bumping my post from yesterday, can anyone help me solve this?
  9. Yeah, I have to admit some of your code is somewhat confusing to me haha. It did help get me on the right track I believe. Right now my new code using chunks of the code you gave me is working the same way my old one is, which displays the list in the order they appear in my database. But this is definatly a step in the right direction as before when I mixed our code it did not work at all. Oops - I realized I forgot to comment on your quote haha. I went into a good amount of detail in my previous post so hopefully it will be easy to understand what I am trying to do from that one
  10. Alright I'll probably still need your help haha but don't worry about it. Basically what I am dealing with is a database with 6 columns: "ID"(primary key auto increment), "Selected" (numeric value I would like to place an incrementing number in to list them in ascending order), "dest_name"(Contains the name of the destination to be chosen), "dest_addr"(Contains the address of the chosen destination that will be used in generating a link to google maps), "dest_date"(The date the destination was established - unimportant here but this is an informative website so it is necessary for organization), and the last column is "dest_description"(Contains a description of the destination - also irrelevant). So the outline of the table looks like this: ID Selected in_order dest_name dest_addr dest_date dest_description 1 0 (# depending on order selected) National Gallery of Art 401+Constitution+Ave N/A N/A On my web page is a drop-down list of the destinations in my database, with it's value in the list being equal to it's ID in the database. (ex. "<option value="5">White House Park</option>" is the 5th item stored in my database, having an ID of "5". Each item in the drop-down list is selected one at a time using a submit button. Then, a list of all the destinations chosen is displayed. This was done in my old code by changing the value of the selected destination's "Selected" column in the database from default "0" to "1" then everything with a value of "1" was pulled from the database and displayed in a list. The problem is that I want the list to be in the order they were selected, not in the order they are listed in my database. Any help on figuring out how to do this would be greatly appreciated. Here's my old code using the "selected" column containing either 0's or 1's to create the list (This code works fine, just not in the right order): if($_POST['submitted'] == true) { $destChose = $_POST['destList']; if($destChose >= 1) { mysql_query("update destinations set selected=1 where id={$destChose}"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE selected = '1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } }else{ mysql_query("update destinations set selected=1 where id={$destChose}"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE selected = '1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } echo "<br />"; echo "<br />"; echo "Please select a destination."; } } if($_POST['reset'] == true) { mysql_query("update destinations set selected=0 where selected='1'"); } if($_POST['linkgen'] == true) { $result = mysql_query("SELECT dest_addr FROM destinations WHERE selected = '1'"); $counter = mysql_num_rows($result); echo "<a href=\""; while ($row = mysql_fetch_array($result)) { $address[] = $row["dest_addr"]; } switch($counter) { case 1: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; break; case 2: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; break; case 3: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; break; case "4": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; break; case "5": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; break; case "6": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; break; case "7": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; break; case "8": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; break; case "9": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; break; case "10": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; break; case "11": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; break; case "12": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; break; case "13": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; echo "+to:"; echo $address[12]; break; case "14": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; echo "+to:"; echo $address[12]; echo "+to:"; echo $address[13]; break; default: break; } echo "&pw=2"; echo "\">" . "Directions" . "</a>"; } ?> <html> <head> <title>Create a Tour</title> </head> <body> <br /> <br /> <form name="tourCreation" action="createTour_workingfinal.php" method="post"> Please complete this form to create your tour: <br /> <br /> Destinations:<br /> <select name="destList" size="10"> <option value="1">National Gallery of Art</option> <option value="2">National Archives & Records Administration</option> <option value="3">National Law Enforcement Officers Memorial</option> <option value="4">Kenilworth Aquatic Gardens</option> <option value="5">White House Park</option> <option value="6">Washington Photo Safari</option> <option value="7">Federal Bureau of Investigation</option> <option value="8">Franciscan Monastery - Commissariat of the Holy Land in America</option> <option value="9">National Portrait Gallery Special Events Department</option> <option value="10">Rock Creek Park</option> <option value="11">Anacostia Community Museum</option> <option value="12">National Shrine of the Immaculate Conception </option> <option value="13">U.S. National Arboretum</option> <option value="14">Union Station</option> </select> <br /> <br /> <br /> <input type="submit" name="submitted" value="Select Destination" /> <input type="submit" name="reset" value="Reset" /> <input type="submit" name="linkgen" value="Get Link" /> </form> <br /> <br /> </body> </html> Here's my new code trying to use a counter to update the "in_order" column of my database with ascending numeric values: if($_POST['submitted'] == true) { $destChose = $_POST['destList']; $Col_result = mysql_query("SELECT in_order FROM destinations"); $column_array = mysql_fetch_array($Col_result); $High_column_rank = 0; for($i = 0; $i<14;$i++) { $column_current_rank = $column_array[$i]; if ($column_current_rank > $High_column_rank) {$High_column_rank = $column_current_rank;} } $High_column_rank++; mysql_query("update destinations set in_order= $High_column_rank where id= $destChose"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE in_order >='1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } }else{ mysql_query("update destinations set in_order= $High_column_rank where id={$destChose}"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE in_order >='1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } echo "<br />"; echo "<br />"; echo "Please select a destination."; } if($_POST['reset'] == true) { mysql_query("update destinations set selected=0 where selected='1'"); } if($_POST['linkgen'] == true) { $result = mysql_query("SELECT dest_addr FROM destinations WHERE selected = '1'"); $counter = mysql_num_rows($result); echo "<a href=\""; while ($row = mysql_fetch_array($result)) { $address[] = $row["dest_addr"]; } switch($counter) { case 1: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; break; case 2: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; break; case 3: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; break; case "4": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; break; case "5": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; break; case "6": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; break; case "7": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; break; case "8": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; break; case "9": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; break; case "10": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; break; case "11": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; break; case "12": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; break; case "13": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; echo "+to:"; echo $address[12]; break; case "14": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; echo "+to:"; echo $address[12]; echo "+to:"; echo $address[13]; break; default: break; } echo "&pw=2"; echo "\">" . "Directions" . "</a>"; } ?> <html> <head> <title>Create a Tour</title> </head> <body> <br /> <br /> <form name="tourCreation" action="createTour_inorderRedone.php" method="post"> Please complete this form to create your tour: <br /> <br /> Destinations:<br /> <select name="destList" size="10"> <option value="1">National Gallery of Art</option> <option value="2">National Archives & Records Administration</option> <option value="3">National Law Enforcement Officers Memorial</option> <option value="4">Kenilworth Aquatic Gardens</option> <option value="5">White House Park</option> <option value="6">Washington Photo Safari</option> <option value="7">Federal Bureau of Investigation</option> <option value="8">Franciscan Monastery - Commissariat of the Holy Land in America</option> <option value="9">National Portrait Gallery Special Events Department</option> <option value="10">Rock Creek Park</option> <option value="11">Anacostia Community Museum</option> <option value="12">National Shrine of the Immaculate Conception </option> <option value="13">U.S. National Arboretum</option> <option value="14">Union Station</option> <option value="23">Tommy J</option> </select> <br /> <br /> <br /> <input type="submit" name="submitted" value="Select Destination" /> <input type="submit" name="reset" value="Reset" /> <input type="submit" name="linkgen" value="Get Link" /> </form> <br /> <br /> </body> </html> tl;dr - That is an overview of how my database is set up / my goals / two sets of my code. If you need anymore details feel free to ask.
  11. Yes, I believe so. As long as destChose1 is not necessarily the first item in my database, but rather the first item selected by the user. (Meaning they could select the 5th item in the list and that would be destChose1).
  12. Yes I've been having a lot of logic problems, I am still somewhat new to php and MySQL but thank you I think this helped to get me a step closer.
  13. This... it looks like you removed it in your new code because you have it in your old code Nice! Good catch. I re-defined it in my new code and now I am able to update the in_order column of my database, however some of them change to 1s and others change to 2s when they are selected from the list. I want them to change to incrementing numbers (1,2,3,4,ect) Any ideas on how to fix this?
  14. Thanks, I moved it, does this look better? if($_POST['submitted'] == true) { $Col_result = mysql_query("SELECT in_order FROM destinations"); $column_array = mysql_fetch_array($Col_result); $High_column_rank = 0; for($i = 0; $i<14;$i++) { $column_current_rank = $column_array[$i]; if ($column_current_rank > $High_column_rank) {$High_column_rank = $column_current_rank;} } $High_column_rank++; ** mysql_query("update destinations set in_order= $High_column_rank where id= $destChose"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE in_order >='1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } }else{ mysql_query("update destinations set in_order= $High_column_rank where id={$destChose}"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE in_order >='1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } echo "<br />"; echo "<br />"; echo "Please select a destination."; }
  15. Yeah my bad on the pluses I meant to put *'s there to show I changed the line. And I think you're right about it being a logic problem, however I am unsure how to fix this. Most of this is code someone helped me create, my original code is here: if($_POST['submitted'] == true) { $destChose = $_POST['destList']; if($destChose >= 1) { mysql_query("update destinations set selected=1 where id={$destChose}"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE selected = '1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } }else{ mysql_query("update destinations set selected=1 where id={$destChose}"); $result = mysql_query("SELECT dest_name, dest_addr FROM destinations WHERE selected = '1'"); while ($row = mysql_fetch_array($result)) { echo "<li>"; echo $row["dest_name"]; echo "</li>"; } echo "<br />"; echo "<br />"; echo "Please select a destination."; } } if($_POST['reset'] == true) { mysql_query("update destinations set selected=0 where selected='1'"); } if($_POST['linkgen'] == true) { $result = mysql_query("SELECT dest_addr FROM destinations WHERE selected = '1'"); $counter = mysql_num_rows($result); echo "<a href=\""; while ($row = mysql_fetch_array($result)) { $address[] = $row["dest_addr"]; } switch($counter) { case 1: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; break; case 2: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; break; case 3: echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; break; case "4": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; break; case "5": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; break; case "6": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; break; case "7": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; break; case "8": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; break; case "9": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; break; case "10": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; break; case "11": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; break; case "12": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; break; case "13": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; echo "+to:"; echo $address[12]; break; case "14": echo "http://maps.google.com/maps?f=d&source=s_d"; echo "&saddr="; echo $address[0]; echo "&daddr="; echo $address[1]; echo "+to:"; echo $address[2]; echo "+to:"; echo $address[3]; echo "+to:"; echo $address[4]; echo "+to:"; echo $address[5]; echo "+to:"; echo $address[6]; echo "+to:"; echo $address[7]; echo "+to:"; echo $address[8]; echo "+to:"; echo $address[9]; echo "+to:"; echo $address[10]; echo "+to:"; echo $address[11]; echo "+to:"; echo $address[12]; echo "+to:"; echo $address[13]; break; default: break; } echo "&pw=2"; echo "\">" . "Directions" . "</a>"; } ?> <html> <head> <title>Create a Tour</title> </head> <body> <br /> <br /> <form name="tourCreation" action="createTour_workingfinal.php" method="post"> Please complete this form to create your tour: <br /> <br /> Destinations:<br /> <select name="destList" size="10"> <option value="1">National Gallery of Art</option> <option value="2">National Archives & Records Administration</option> <option value="3">National Law Enforcement Officers Memorial</option> <option value="4">Kenilworth Aquatic Gardens</option> <option value="5">White House Park</option> <option value="6">Washington Photo Safari</option> <option value="7">Federal Bureau of Investigation</option> <option value="8">Franciscan Monastery - Commissariat of the Holy Land in America</option> <option value="9">National Portrait Gallery Special Events Department</option> <option value="10">Rock Creek Park</option> <option value="11">Anacostia Community Museum</option> <option value="12">National Shrine of the Immaculate Conception </option> <option value="13">U.S. National Arboretum</option> <option value="14">Union Station</option> </select> <br /> <br /> <br /> <input type="submit" name="submitted" value="Select Destination" /> <input type="submit" name="reset" value="Reset" /> <input type="submit" name="linkgen" value="Get Link" /> </form> <br /> <br /> </body> </html> The problem with this code is that I can't get the items chosen from my drop-down list to display in the order they were selected, so I was mixing my code with my helper's to try to update the "in_order" column in the database for each item selected. This "in_order" column is supposed to be updated with a counter however I am having trouble getting the code to work, and I don't understand a lot of the new code that was added.
×
×
  • 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.