Jump to content

Skipjackrick

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Everything posted by Skipjackrick

  1. You didn't provide any details about how you were going to use this information. If it were me I would be storing this information in a database. And, if you are doing that then the ID should be dictated by the ID in the database and not dynamically generated via JavaScript Sorry, I don't mean to sound like I am complaining. This will work perfect. I really appreciate your help. I have no idea how to setup php to populate my form. However, the database has a table labeled "angler" that has 3 fields. ID : NAME : TEAM_ID If I could ever get good enough at php I would just get the page to reload the second drop down according to the Team_ID. Do you know of a good tutorial on dynamic drop down boxes? This is probably not the appropriate place for this question though.
  2. Sweet! Thanks mjdamato!!! Works Perfect! However, the only problem is if in the future the anglers decide to switch teams on me it won't be possible to use this code. But its simple and neat!
  3. Ooopps Sorry about that. I actually did finally test the code. I didn't see that small change you put in there. My apologies. It gave me the correct output When I chose Team #1 and the first angler. Output was "2" It gave me the correct output When I chose Team #1 and the 3rd angler. Output was "4" However, it gave me the exact same output for Team #2 and the first angler. Output was "2" Where, That angler should actually be "7" Thanks so much for help. I really appreciate it.
  4. Did you change anything? Doesn't seem to be any changes? Basically i have a MySQL database that now lists the anglers 1, 2, 3, 4, 5, 6, 7, 8, etc. This way I can use a relational key to help display data in other pages. I can't figure out how to make this javascript output the numeric value in the form...... However, display the name of the angler in the page.
  5. I have a small javascript that will fill in the names of the anglers on a team after they choose a specified team. However, I have reworked my database and now I would like the javascript to actually put a "value" in place of the anglers name. Does anybody know how to make javascript set an "option value" yet display the actual name on the page????? Currently the array looks like this teamLists["1"] = ["", "Oz", "Skipjack", "Curmit", "Old Salt", "Kip",]; What I want is this teamLists["1"] = ["", "1", "2", "3", "4", "5",]; However, I want the user to see this on the page when they select team #1. <option value="1">Oz</option> <option value="2">Skipjack</option> <option value="3">Curmit</option> <option value="4">Old Salt</option> <option value="5">Kip</option> Does this make sense? <script type="text/javascript"> //<![CDATA[ // array of possible team in the same order as they appear in the team selection list var teamLists = new Array(5) teamLists["empty"] = ["Select Angler"]; teamLists["1"] = ["", "Oz", "Skipjack", "Curmit", "Old Salt", "Kip",]; teamLists["2"] = ["", "Jolly Roger", "Oscar", "Altonr77", "Northpaw", "Cabeza de Vaca"]; teamLists["3"] = ["", "Puretexn", "ShawnQ", "Mando", "Cowboy", "Alamo"]; teamLists["4"] = ["", "Chazbo", "Bigfost", "Fla-Fish", "DancingWithBulls Sr.", "DancingWithBulls"]; teamLists["5"] = ["", "Artofficial", "Easily Yakked", "PierPressure", "FishinFools(Herb)", "FishinFools(Jan)"]; teamLists["6"] = ["", "Rod Dawg", "Latestart", "Aceshooter", "Randy", "Arnulfo"]; teamLists["7"] = ["", "Masonator", "Chainzter", "Roel115", "Gill Ripper", "Greatwhite72"]; teamLists["8"] = ["", "Krakatoa", "El Gallo", "Junior"]; teamLists["9"] = ["", "Johnny A", "Stray", "NickleBait", "Socom", "KiDd"]; teamLists["10"] = ["", "Yakmon", "Mr. Champ", "RaiderRed", "Repofish", "Shindle"]; /* teamChange() is called from the onchange event of a select element. * param selectObj - the select object which fired the on change event. */ function teamChange(selectObj) { // get the index of the selected option var idx = selectObj.selectedIndex; // get the value of the selected option var which = selectObj.options[idx].value; // use the selected option value to retrieve the list of items from the teamLists array cList = teamLists[which]; // get the team select element via its known id var cSelect = document.getElementById("angler"); // remove the current options from the team select var len=cSelect.options.length; while (cSelect.options.length > 0) { cSelect.remove(0); } var newOption; // create new options for (var i=0; i<cList.length; i++) { newOption = document.createElement("option"); newOption.value = cList[i]; // assumes option string and value are the same newOption.text=cList[i]; // add the new option try { cSelect.add(newOption); // this will fail in DOM browsers but is needed for IE } catch (e) { cSelect.appendChild(newOption); } } } //]]> </script> <select name="team_id" id="team_id" onChange="teamChange(this);"> <option value="0">Select Team</option> <option value="1">Rockstar</option> <option value="2">Plastic Pirates</option> <option value="3">Lone Star Sharkers</option> <option value="4">Roadrunner</option> <option value="5">Hawg Wild</option> <option value="6">Mojo</option> <option value="7">TAMUK Anglers</option> <option value="8">Krakatoa</option> <option value="9">Why Knot</option> <option value="10">Kraken</option> </select> <select name="angler" id="angler"> <option value="0">Select Angler</option>
  6. Ok, I have hacked away at this for an hour trying to figure out how to get this to work. No luck. How do I get the new variables in the query? It just doesn't work for me. I keep getting syntax errors. and I think its right here ---> $query_anglertotals = "SELECT species_id, SUM(IF(angler='$results[0]['angler']',1,0)) AS anglerA, This is my code. <?php //Connect to MySQL include '/home/extremf3/dbconnect.php'; $query = "SELECT angler, team_id FROM anglers WHERE team_id=1 GROUP BY angler LIMIT 5"; $anglervar = mysql_query($query) or die(mysql_error()); // run a loop, to get each row: while($row = mysql_fetch_assoc($anglervar)) { $results[] = $row; } $query_anglertotals = "SELECT species_id, SUM(IF(angler='$results[0]['angler']',1,0)) AS anglerA, SUM(IF(angler='$results[1]['angler']',1,0)) AS anglerB, SUM(IF(angler='$results[2]['angler']',1,0)) AS anglerC, SUM(IF(angler='$results[3]['angler']',1,0)) AS anglerD, SUM(IF(angler='$results[4]['angler']',1,0)) AS anglerE, SUM(IF(team_id=1,1,0)) AS teamtotal FROM submit WHERE species_id<25 AND yyyy=2008 AND team_id=1 GROUP BY species_id ORDER BY species_id"; $anglertotals = mysql_query($query_anglertotals) or die(mysql_error()); while($row = mysql_fetch_array($anglertotals)) { $anglerA = $row['anglerA']; $anglerB = $row['anglerB']; $anglerC = $row['anglerC']; $anglerD = $row['anglerD']; $anglerE = $row['anglerE']; $teamtotal = $row['teamtotal']; $species_id = $row['species_id']; get_species($species_id); $kayakwars_totals2 .=<<<EOD <tr> <td align='center'>$speciesname</td> <td align='center'>$anglerA</td> <td align='center'>$anglerB</td> <td align='center'>$anglerC</td> <td align='center'>$anglerD</td> <td align='center'>$anglerE</td> <td align='center'>$teamtotal</td> </tr> EOD; } ?>
  7. Cool, So my result looks like this Array ( [0] => Array ( [0] => 1 [angler] => 1 [1] => 1 [team_id] => 1 ) [1] => Array ( [0] => 2 [angler] => 2 [1] => 1 [team_id] => 1 ) [2] => Array ( [0] => 3 [angler] => 3 [1] => 1 [team_id] => 1 ) ) How do I utilize this through the rest of my page? Would I just put $row0 or $row2 In the spots I want that particular variable?
  8. Cool Thanks for the info. I did change everything to .php extensions because that was mentioned earlier. Then I guess after I constructed the code correctly it worked. Multiple problems I guess. Thanks for the help guys.
  9. $anglerA <-would be the variable holding the value from the query result. The result from the query would probably look like this <?php $query = "SELECT angler, team_id FROM anglers WHERE team_id=1 GROUP BY angler LIMIT 4; $angler = mysql_query($query) or die(mysql_error()); ?> Result from query Oz Skip Scott Curtis Then I want to have php do this $anglerA = Oz $anglerB = Skip $anglerC = Scott $anglerD = Curtis
  10. I didn't think so either. Nevertheless, must have had an error then. Because I just copied and pasted that into my page and it worked like a champ.
  11. Basically something like this... Query the database to get the info..... <?php $query = "SELECT angler, team_id FROM anglers WHERE team_id=1 GROUP BY angler LIMIT 4; $angler = mysql_query($query) or die(mysql_error()); ?> Then make the result variables. For example, $anglerA = 1st result $anglerB = 2nd result $anglerC = 3rd result $anglerD = 4th result This way I could use the variables throughout the code in the remaining page. I am not sure how to do this?
  12. Well, I guess I will just bypass this and just manually type all of the db info into each page. I give up.
  13. What is even weirder....Is that if I just paste the connection code directly into the page. It works just fine??? See http://www.extremecoast.com/KW09/anglerstandings2.php
  14. Well, when I added the <?php ?> to the file its not displayed on the webpage. However, it still won't connect to MySQL. I changed the " .inc " extension to ".php" just to elminate any further questioning. My dbconnect file <?php // Database Variables $dbhost = "localhost"; $dbuser = "aaaaaa"; $dbpass = "aaaaaaaaaaaaa"; $dbname = "aaaaaaaa"; $MYSQL_ERRNO = ""; $MYSQL_ERROR = ""; // Connect To Database function db_connect() { global $dbhost, $dbuser, $dbpass, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbuser, $dbpass); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = "Connection failed to $dbhost."; return 0; } else if(!mysql_select_db($dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } // Handle Errors function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return "$MYSQL_ERRNO: $MYSQL_ERROR"; } // Print Error Message function error_message($msg) { printf("Error: %s", $msg); exit; } // Connection String Example # $link_id = db_connect($dbname); # if(!$link_id) error_message(sql_error()); # # $query = "SELECT * FROM test_table"; # $result = mysql_query($query); # # if(!$result) error_message(sql_error()); # # $data = mysql_fetch_array($result); ?>
  15. Nope, I've used this format before and it has worked for me in the past. However, I did try your suggestion and it gave me the same result. http://www.extremecoast.com/KW09/anglerstandings2.php
  16. So as usual, I am including my Database connection file at the beginning of my db queries.....and its just displaying the code on the webpage???? Do any of you have an explanation for this? Take a look???? http://www.extremecoast.com/KW09/anglerstandings.php Just a short snippet of the code. </HEAD> <BODY BGCOLOR="#2f2f2f" TEXT="#ffffff" LINK="#0080ff" VLINK="#0080c0"> <?php include '/home/extremf3/public_html/layout/v2/kwheader.php'; ?> <img src="http://extremecoast.com/layout/v2/anglerstandings.jpg" border="0" align="middle"> <?php include '/home/extremf3/public_html/layout/v2/menu09.php'; ?> <TABLE width="765" border="0" cellpadding="8" align="middle" bgcolor="#343434"> <TR> <TD> <div id="content-wrap"> <div id="main"> <?php include '/home/extremf3/dbconnect.inc'; function get_angler_handle() { global $angler; global $anglerhandle; $query_d = "SELECT handle FROM anglers WHERE angler='$angler'"; $results_d = mysql_query($query_d) or die(mysql_error()); $row_d = mysql_fetch_array($results_d); extract ($row_d); $anglerhandle = $handle; } ?>
  17. Yes! Thanks, wow I thought I was just going to have to start over. Can't learn until you make mistakes I guess. Do you guys have some sort of code check program? How can you spot stuff like that? Or is it just plain experience?
  18. I've been racking my brain trying to figure out why my simple form won't post. It just continues to bring me back to the initial page. I need a pair of fresh eyes. Can anybody do a quick scan and tell me what might be wrong? Anglers start at 101 http://www.ectackle.com/Sharkathon/catchlog.php <?php include 'auth.inc.php'; #################################################################### ################ DATABASE CONFIGURE ############################## #################################################################### $hostname = "localhost"; $db_user = "********"; $db_password = "*********"; $db_table = "catch_log"; # STOP HERE #################################################################### # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db ("********") or die (mysql_error()); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <link rel="SHORTCUT ICON" href="layout/favicon.ico" /> <link rel="stylesheet" href="layout/layout.css" type="text/css" /> <title>Sharkathon Catch Log Database</title></head> <body> <div id="wrap"> <!--header --> <div id="header"> <h1 id="logo-text"></h1> </div> <?php if($_GET['user_id']){ $error = null; if($result = mysql_query(sprintf("SELECT * FROM user_info WHERE user_id = '%s' LIMIT 1",mysql_real_escape_string($_GET['user_id'])))){ $c = mysql_fetch_assoc($result); if(!$c){ $error = "Angler not found"; } }else{ $error = "Query Failed"; } } ?> <!-- menu --> <div id="content-wrap"> <div id="main"> <form method="GET" action=""> Lookup By Contestant ID: <input type="text" name="user_id" /> <input type="submit" value="Lookup" /><br /> <?php if($error) echo '<p style="color:red;">Error: '.$error.'</p>'; ?> </form> <p> </p> <?php if (isset($_POST['Submit'])) { $entry_id = $_POST['entry_id']; $user_id = $_POST['user_id']; $name = $_POST['name']; $shark = $_POST['shark']; $red = $_POST['red']; $trout = $_POST['trout']; $kids = $_POST['kids']; $ladies = $_POST['ladies']; $tarpon = $_POST['tarpon']; $date = $_POST['date']; $bait = $_POST['bait']; $species = $_POST['species']; $length = $_POST['length']; $fork = $_POST['fork']; $location = $_POST['location']; $time = $_POST['time']; # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO catch_log(entry_id, user_id, name, shark, red, trout, kids, ladies, tarpon, date, bait, species, length, fork, location, time) values ('$entry_id', '$user_id', '$name', '$shark', '$red', '$trout', '$kids', '$ladies', '$tarpon', '$date', '$bait', '$species', '$length', '$fork', '$location', '$time')"; if($result = mysql_query($sql ,$db)) { echo "<br>"; echo "Thank you, Your information has been entered into the database."; echo "<br>"; echo "<br>"; echo "<a href='http://www.ectackle.com/Sharkathon/catchlog.php'>"; echo "Click here to make another submission"; echo "</a>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; } else { echo "ERROR: ".mysql_error(); } } else { ?> <form action="" enctype="multipart/form-data" name="form" id="form" method="POST"> <input type="hidden" name="entry_id" value="NULL"> <div align="center">Name: <input name="name" type="text" value="<?php echo htmlspecialchars($c['name']); ?>" /> Shark: <input name="shark" type="text" value="<?php echo htmlspecialchars($c['shark']); ?>" size="1" maxlength="2" /> Redfish: <input name="red" type="text" value="<?php echo htmlspecialchars($c['red']); ?>" size="1" maxlength="2" /> Trout: <input name="trout" type="text" value="<?php echo htmlspecialchars($c['trout']); ?>" size="1" maxlength="2" /> Kids: <input name="kids" type="text" value="<?php echo htmlspecialchars($c['kids']); ?>" size="1" maxlength="2" /> Ladies: <input name="ladies" type="text" value="<?php echo htmlspecialchars($c['ladies']); ?>" size="1" maxlength="2" /> Tarpon: <input name="tarpon" type="text" value="<?php echo htmlspecialchars($c['tarpon']); ?>" size="1" maxlength="2" /> </div> <p> </p> <div align="center"> <p>Date: <select name="date" id="date" > <option value="0">Select a Date</option> <option value="100308">10/03/2008</option> <option value="100408">10/04/2008</option> <option value="100508">10/05/2008</option> </select> Bait: <select name="selection" id="selection" > <option value="0">Select a Bait</option> <option value="Ladyfish">Ladyfish</option> <option value="Stingray">Stingray</option> <option value="Whiting">Whiting</option> <option value="Mullet">Mullet</option> <option value="Sand Trout">Sand Trout</option> <option value="Sheepshead">Sheepshead</option> </select> Species: <select name="species" id="species" > <option value="0">Select a Species</option> <option value="Blacktip">Blacktip</option> <option value="Bull">Bull</option> <option value="Sharpnose">Sharpnose</option> <option value="Trout">Trout</option> <option value="Redfish">Redifsh</option> <option value="Tiger">Tiger</option> <option value="Tarpon">Tarpon</option> <option value="Ladyfish">Ladyfish</option> <option value="Stingray">Stingray</option> <option value="Whiting">Whiting</option> <option value="Mullet">Mullet</option> <option value="Sand Trout">Sand Trout</option> <option value="Sheepshead">Sheepshead</option> </select> </p> <p><br /> Length: <input type="text" id="length" size="4" maxlength="5" /> Re-Verify Length: <input type="text" id="length2" size="4" maxlength="5" /> Fork: <input type="text" id="fork" size="4" maxlength="5" /> Location: <input type="text" id="location" size="4" maxlength="5" /> Time: <input type="text" id="time" size="4" maxlength="5" /> <br> <br> <br> <input type="Submit" value="Submit" /> <br /> </p> </div> </form> <?php } ?> </div> <!-- content-wrap ends here --> </div> <!--footer starts here--> <div id="footer"> <p> © 2009 <strong>Sharkathon</strong>| Design by: sharkathon.com</p> </div> <!-- wrap ends here --> </div> <div style="font-size: 0.8em; text-align: center; margin-top: 1.0em; margin-bottom: 1.0em;"></div> </body> </html>
  19. AUESOME!!!!!!!! Thanks a million!!!!! Topic solved.
  20. When you say list? Is there some syntax for just listing the table needed? Like this? <?php $sql = "SHOW TABLES FROM namelookup"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } ?> I am setting this up for a fishing competition. We will have the names of the participants before the event starts. Once they arrive, we will populate the table "check-in" with the appropriate data. I want the form to populate the name of the contestant by using the "user_id". Each contestant was given a user id number to speed up the check-in process. DB = namelookup DB contains two tables "user_info" and "check_in" "user_info" has two fields user_id name "check_in" has 7 fields entry_id = Primary key (auto increment) user_id name time division tshirt age
  21. "user_id" and "name" I have another table in my DB that also has a field called "user_id". I am guessing this can't be done..LOL
×
×
  • 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.