Jump to content

mtnmchgrl

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Everything posted by mtnmchgrl

  1. I just sent it in a message to you. Thank you! Anyone else?? The problem jumped out at me once I tried to run it. You cannot do an INSERT...WHERE. That would imply that you already have a row that meets the WHERE criteria in which case you do an UPDATE. It would be UPDATE stats set atBats='$abats', hits = '$hits', walks='$walks', RBI= '$RBI', strkOuts='$strkOuts', singles='$singles', doubles='$doubles', triples='$triples', homeRuns='$homeruns', runsScrd='$runsScrd', fieldersCh='$fieldersCh' where FK_playerID='$FK_playerID' and FK_tourneyID='$FK_tourneyID'; I have just assumed that those are the variable names and if not, you get the drfit. [attachment deleted by admin]
  2. I just sent it in a message to you. Thank you! The problem jumped out at me once I tried to run it. You cannot do an INSERT...WHERE. That would imply that you already have a row that meets the WHERE criteria in which case you do an UPDATE. It would be UPDATE stats set atBats='$abats', hits = '$hits', walks='$walks', RBI= '$RBI', strkOuts='$strkOuts', singles='$singles', doubles='$doubles', triples='$triples', homeRuns='$homeruns', runsScrd='$runsScrd', fieldersCh='$fieldersCh' where FK_playerID='$FK_playerID' and FK_tourneyID='$FK_tourneyID'; I have just assumed that those are the variable names and if not, you get the drfit. That makes sense b/c the first 2 fields already exist!!! However, I just did this and I'm still getting an error. Plus the query to actually insert the records doesn't contain a WHERE. The select statement below that (that shows all the stats) is the one that has the where and it is working just fine. Its the first query that is not working.....the one to add stuff to the db. Man i thought this was really going to fix it too. Grrrr....
  3. lol, well I guess it's a personally prefernce, but standard check boxes look kind of tacky. I do graphic design, so designing a button is convenient. All it is basically, you click it, and the button turns white, and then you click it again, and it turns black. After that, I want to get the value of the button, where it is white or black (checked or not checked) (clicked or not clicked, lol) . Hmm....I did something kind of like this using CSS. My nav bar....the link buttons when not clicked are one color and when clicked, they display an image.....is that kind of what you mean ?
  4. Yes, I use xampp/apache to run this site...just local host. Can I use either of those programs with that?? I have access to PHPMyAdmin but I hate using it...I ended up doing all my tables from scratch in command line. Sigh.....
  5. I tested that. No problems with the inputted data, so it has to be my query.....am I referencing the foreign keys right? Remember, the 2 foreign keys referenced are linked to 2 different tables.......to me it would make sense to right sql query like: mysql> insert into stats (FK_tourneyID, FK_playerID, atBats, hits, walks, RBI, strkOuts, singles, do ubles, triples, homeRuns, runsScrd, fieldersCh) VALUES (1, 13, 10, 3, 1, 0, 0, 1, 1, 1, 0, 0, 0) w here FK_playerID=13 and FK_tourneyID=1; But this does not seem to work. I also took off the FK_ and it didn't work either. Any help would be appreciated.... [attachment deleted by admin]
  6. 1. All the entries are numbers (whole) with the exception of the playerFN/LN which is linked to playerID (which is a #) and the tournament name which is linked by tourneyID. not sure if those two matter as they are existing fields in db? 2. Not sure if I understood your thing about the quotes, but I took off the quotes on the column names (the first set of parenthesis in the INSERT statement (before values). 3. There aren't any strings being entered so I don't think there is a need for the mysql_real_escape_string() at all 4. I changed my query to just show all 10 players and ALL their stats (100 records total). For some reason my atBats column isn't showing up although i don't see anything weird..... 5. No longer getting parser/syntax error but we are back to this error: The following errors occured: * Doubles are required. * Triples are required. * Home Runs are required. * Runs Scored are required. * Fielders Choice is required. So close....anyone else??? Modifed attached. [attachment deleted by admin]
  7. Ok, caught that and a few other little things. Form is showing up w/out the parse/syntax error page but its still not submitting properly. Nothing gets submitted and I get these errors: The following errors occured: * Home Runs are required. * Runs Scored are required. * Fielders Choice is required. Think there is something wonky w/ my query too b/c its not filling up right at the bottom. It should show the last entered record..... Getting closer......... What syntax editor do you use? I use Crimson Editor and Dreamweaver. DW sucks for this kind of stuff. What do you recommend? Re attaching new .php [attachment deleted by admin]
  8. Hello again, I just realized this didn't make sense. On this form, I am adding statistics for each game and player. The name of the tournament and the player is already in the db (b/c you can't add stats on games that don't exist). So all the person sees is 2 drop downs and then the stat input boxes. The first drop down should be the name of the tournament. The second drop down is the players first and last names (which is a concatenation of the playerFN, playerLN columns). While it looks like alot I am certain the input fields are set up correctly considering they are the same from the other form. I am unsure about the <option select> drop down fields and how i have that set up. I did have the drop downs working before but the adding of new records would not work. That was before i reworked the data from that previous thread. This is the last one I am working on so if anyone could help again I would be VERY appreciative....... The drop downs are toward the bottom of the page w/ all the input field code. I tried to run this and it gave me this error: Parse error: syntax error, unexpected T_STRING, expecting ']' in L:\addStats.php on line 183 Line 183 is this: <?php include_once('includes/admin_nav.inc.php'); ?> So that makes no sense.... <?php // START SESSION require_once('includes/session.inc.php'); // CONNECT TO DATABASE require_once('includes/connect.inc.php'); // PROCESS FORM ON SUBMIT $response = ''; if (isset($_POST['submit'])) { //Create array var to capture errors $errors = array(); //VALIDATE THE SUBMITTED DATA $tournID = trim($_POST['tourneyID']); $playID = trim($_POST['playerID']); $AB = trim($_POST['atBats']); $H = trim($_POST['hits']); $W = trim($_POST['walks']); $RBI = trim($_POST['RBI']); $SO = trim($_POST['strkOuts']); $S = trim($_POST['singles']); $D = trim($_POST['doubles']); $T = trim($_POST['triples']); $hR = trim($_POST['homeRuns']); $rS = trim($_POST['runsScrd']); $fCh = trim($_POST['fieldersCh']); //IF STATEMENTS TO CHECK FOR EMPTY FIELDS if(empty($tournID)) { $errors[] = "Tournament ID is required."; } if(empty($playID)) { $errors[] = "Player ID is required."; } if(empty($AB)) { $errors[] = "At Bats are required."; } if(empty($H)) { $errors[] = "Hits are required."; } if(empty($W)) { $errors[] = "Walks are required."; } if(empty($RBI)) { $errors[] = "RBI is required."; } if(empty($SO)) { $errors[] = "Strike Outs are required."; } if(empty($S)) { $errors[] = "Singles are required."; } if(empty($D)) { $errors[] = "Doubles are required."; } if(empty($T)) { $errors[] = "Triples are required."; } if(empty($hR)) { $errors[] = "Home Runs are required."; } if(empty($rS)) { $errors[] = "Runs Scored are required."; } if(empty($fCh)) { $errors[] = "Fielders Choice is required."; } //IF THE THE NUMBER OF ERRORS IS GREATER THAN ZERO, THEN THE MESSAGES WILL DISPLAY IN THIS FASHION... if(count($errors)>0) { //There were validation errors, prepare error message $response = "<span style=\"color:red;\">"; $response .= "The following errors occured:\n"; $response .= "<ul>"; $response .= '<li>' . implode('</li><li>', $errors) . '</li>'; $response .= "</ul>\n"; $response .= "</span>\n"; } else { //IF NO VALIDATION ERRORS, SAVE INPUT DATA TO DATABASE $tournID = mysql_real_escape_string($tournID); $playID = mysql_real_escape_string($playID); $AB = mysql_real_escape_string($AB); $H = mysql_real_escape_string($H); $W = mysql_real_escape_string($W); $RBI = mysql_real_escape_string($RBI); $SO = mysql_real_escape_string($SO); $S = mysql_real_escape_string($S); $D = mysql_real_escape_string($D); $T = mysql_real_escape_string($T); $hR = mysql_real_escape_string($hR); $rS = mysql_real_escape_string($rS); $fCh = mysql_real_escape_string($fCh); // QUERY TO RETRIEVE ENTRY RESULTS $query="INSERT INTO `stats` (`tourneyID`, `playerID`, `atbats`, `hits`, `walks`, `RBI`, `strkOuts`, `singles`, `doubles`, `triples`, `homeRuns`, `runsScrd`, `fieldersCh`) VALUES ('{$tournID}', '{$playID}', '{$AB}', '{$H}', '{$W}', '{$RBI}', '{$SO}', '{$S}', '{$T}', '{$hR}', '{$rS}', '{$fCh}')"; $result = mysql_query($query); if (!$result) { $response = "No record was added. Please try again."; $response .= "<br />\n$query<br />".mysql_error(); } else { $response = "The record has been added."; } } } //GET CURRENT RECORDS TO DISPLAY - THIS WILL SHOW ME THE LAST ROW I ENTERED $query = "SELECT playerID, playerFN, playerLN, tourneyID, tourneyName, atbats, hits, walks, RBI, strkOuts, singles, doubles, triples, homeRuns, runsScrd, fieldersCh FROM `player`, `tournaments`, `stats` WHERE player.playerID=stats.FK_playerID AND tournaments.tourneyID=stats.FK_tourneyID ORDER BY playerID DESC LIMIT 1"; $result = mysql_query($query); //VALIDATE THERE WERE RECORDS if(mysql_num_rows($result) == 0) { $records = "Sorry, no records were found!"; } else { // START OF TABLE, HEADERS, ETC $records = "<table border=\"1\">\n"; $records .= "<tr><th>TourneyID</th><th>PlayerID</th><th>AB</th><th>H</th><th>W</th><th>RBI</th><th>SO</th><th>S</th><th>D</th><th>T</th><th>HR</th><th>RS</th><th>FC</th></tr>\n"; //LOOP THE DATABASE TO DISPLAY THE RECORDS while ($myrow = mysql_fetch_array($result)) { //PRINT RESULTS $records .= "<tr>"; $records .= "<td>{$myrow['tourneyID']}</td>"; $records .= "<td>{$myrow['playerID']}</td>"; $records .= "<td>{$myrow['atBats']}</td>"; $records .= "<td>{$myrow['hits']}</td>"; $records .= "<td>{$myrow['walks']}</td>"; $records .= "<td>{$myrow['RBI']}</td>"; $records .= "<td>{$myrow['strkOuts']}</td>"; $records .= "<td>{$myrow['singles']}</td>"; $records .= "<td>{$myrow['doubles']}</td>"; $records .= "<td>{$myrow['triples']}</td>"; $records .= "<td>{$myrow['homeRuns']}</td>"; $records .= "<td>{$myrow['runsScrd']}</td>"; $records .= "<td>{$myrow['fieldersCh]}</td>"; $records .= "</tr>\n"; } $records .= "</table>\n"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Admin MySQL Database</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/admin.css" rel="stylesheet" type="text/css"> </head> <body> <div id="navigation"> <?php include_once('includes/admin_nav.inc.php'); ?> </div> <!--END NAVIGATION DIV--> <div id="content"> <h1>Add Statistics</h1> <br /> <div><?php echo $response; ?></div> <!--HTML FORM FOR ENTRY OF THE STATS!--> <form method="post" action=""><!--addStats.php--> <p>Select Tournament: <select name="tourneyID"> <?php // CONNECT TO DATABASE require_once('includes/connect.inc.php'); //THIS QUERY GETS tourneyID, tourneyName and gameDate from tournaments table. $result = mysql_query("SELECT * FROM tournaments"); while ($myrow = mysql_fetch_array($result)) { //THIS IS MY DROP DOWN WHERE THE PERSON SHOULD SELECT THE NAME OF THE EXISTING TOURNAMENT. echo'<option value="'.$myrow['tourneyID'].'">'.$myrow['tourneyName'].'</option>'; } ?> </select> </p> <p>Select Player: <select name="playerID"> <?php //THIS QUERY GETS FIRST THREE FIELDS OF PLAYER TABLE $result = mysql_query("SELECT playerID, playerFN, playerLN FROM player"); while ($myrow = mysql_fetch_array($result)) { //THIS IS MY DROP DOWN SHOWING THE CONCATENATED PLAYERS FIRST AND LAST NAME echo'<option value="'.$myrow['playerID'].'">'.$myrow['playerFN'].' '.$myrow['playerLN'].'</option>'; } ?> </select></p> <!--HERE IS WHERE THE INPUT FIELDS FOR EACH STATISTIC WILL GO - DATA THAT IS TO BE ENTERED AND IS NOT ALREADY IN db--> <table border=1 RULES=NONE FRAME=BOX> <tr> <td>At Bats:</td> <td><input type="text" name="atBats" size="20" maxlength="20"></td> </tr> <tr> <td>Hits:</td> <td><input type="text" name="hits" size="20" maxlength="20"></td> </tr> <tr> <td>Walks:</td> <td><input type="text" name="walks" size="20" maxlength="20"></td> </tr> <tr> <td>RBI:</td> <td><input type="text" name="RBI" size="20" maxlength="20"></td> </tr> <tr> <td>Strike Outs:</td> <td><input type="text" name="strkOuts" size="20" maxlength="20"></td> </tr> <tr> <td>Singles:</td> <td><input type="text" name="singles" size="20" maxlength="20"></td> </tr> <tr> <td>Doubles:</td> <td><input type="text" name="doubles" size="20" maxlength="20"></td> </tr> <tr> <td>Triples:</td> <td><input type="text" name="triples" size="20" maxlength="20"></td> </tr> <tr> <td>Home Runs:</td> <td><input type="text" name="homeRuns" size="20" maxlength="20"></td> </tr> <tr> <td>Runs Scored:</td> <td><input type="text" name="runsScrd" size="20" maxlength="20"></td> </tr> <tr> <td>Fielders Choice:</td> <td><input type="text" name="fieldersCh" size="20" maxlength="20"> </td> </tr> </table> <br /> <input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset Values"> </form> <br /> <?php echo $records; ?> </div> <!--END CONTENT DIV--> </body> </html> [attachment deleted by admin]
  9. One quick thing I don't understand.....below where the HTML form comment is and there is a form method post statement.... <form method="post" action="">addTournament2.php How come the .php file is outside of the form method brackets?? How does that work? Everything else for the most part makes sense and its definitely in a hell of a lot more organized fashion. Perhaps as I become better at this I will be able to produce something similiar. Sigh. Sorry, bout that. I removed the file name from the action so I could have the page POST to itself for testing purposes. You can replace that value or leave it blank if the page is supposed top post to itself. // PROCESS FORM ON SUBMIT $response = ''; if (isset($_POST['tourneyName'])) No, no relation. In that code, I simply define $respons as an empty string in case it doesn't get defined later. The IF statement is there to process the data only if data was posted. Ok, thank you for that. It helps me better understand so I can try and correct in the future.....Now I have taken what you did and tried to apply it to another form.....its slightly different but should have almost the basic set up. I might post a new thread if I can't get it working! THANKS AGAIN!
  10. ok Cool. And that empty action="" refers to this at the very top right? // PROCESS FORM ON SUBMIT $response = ''; if (isset($_POST['tourneyName']))
  11. One quick thing I don't understand.....below where the HTML form comment is and there is a form method post statement.... <form method="post" action="">addTournament2.php How come the .php file is outside of the form method brackets?? How does that work? Everything else for the most part makes sense and its definitely in a hell of a lot more organized fashion. Perhaps as I become better at this I will be able to produce something similiar. Sigh.
  12. Dear mjdamato, Oh, how I love thee. Let me count the ways. That works perfectly!!! Thank you SOOOOO much. I would have spent another 6 hours trying to go around my you know what to get to my elbow. Thank you, thank you, thank you! I'm not sure how to do this but this thread has been solved! THANK YOU!!!!!!! WOOHOOO!!!!! PS. mjdamato is the bomb.
  13. Hey again, I didn't originally have the NULL in there.....there are 3 columsn in the table....tourneyID is the primary key. I wasn't sure whether i had to reference that or not? Its auto increment so I thought if i left that out and added data for the other 2 fields it would automatically insert a new id#? I tried your modified code w/ the added bracket and THIS TIME I got this error: Catchable fatal error: Object of class DateTime could not be converted to string in L:\addTournament2.php on line 17 I don't know what that means....but just wondering....my already existing dates in the database aren't time stamped...they are just date (yyyy-mm-dd) I think i was putting yyyy-mm-mm on those other posts. 'Excuse. I got 3 hours sleep last night.
  14. When I have tried to test the name/date in my form I have tried entering both yyyy-mm-mm AND mm-mm-yyyy and even yyyymmmm.
  15. I tried this. No parse error screen but the record isn't added. And it says it has been added....but nothing shows up. that part must have to do w/ my success/error statements though. So anyway...that didn't work.
  16. Hey Muddy, Ok, I took out this line: $query="insert into `tournaments` ('tourneyID', 'tourneyName', 'gameDate') values('NULL','(".$_POST['tourneyName']."')', date_format(".$_POST['gameDate']."'%Y-%m-%d') )"; and put in your suggestion and got this error: Parse error: syntax error, unexpected ')', expecting ']' in L:\ on line 16
  17. Hello, I've spent at least 6 hours going back and forth changing this code and I cannot get this to process. The closest I came was that it would enter what I wanted, but the date showed up as 0000-00-00. This is the simplest form. Only 2 columns are being entered from a php input form....a name and a date. Can anyone help? I have already consulted 3 mysql/php books (and RTFM) AND googled away but i cannot find an exact situation like mine....which is hard to believe. I already have my database set for the date to be yyyy-mm-mm and i don't really care how it reads in PHP. I just want the use to be able to enter the thing (yyyy-mm-mm) is fine. MANY thanks.... <?php // START SESSION require_once('includes/session.inc.php'); // PROCESS FORM ON SUBMIT //if (!isset('submit', $_POST)) if (array_key_exists('submit', $_POST)) { //IF THE ARRAY ISN'T EMPTY PRINT ALL THE FIELDS OF THE PLAYER TABLE if(!empty($_POST['tourneyName']) && !empty($_POST['gameDate'])) { // CONNECT TO DATABASE require_once('includes/connect.inc.php'); // QUERY TO RETRIEVE ENTRY RESULTS $query="insert into `tournaments` ('tourneyID', 'tourneyName', 'gameDate') values('NULL','(".$_POST['tourneyName']."')', date_format(".$_POST['gameDate']."'%Y-%m-%d') )"; mysql_query($query); // RESET FLAGS $success = 0; // IF QUERY RUNS CORRECTLY if ($query) {$success = 1;} else {$error=1;}; } else { $success = 0; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Admin MySQL Database For The Bomb Island Raiders</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/admin.css" rel="stylesheet" type="text/css"> </head> <body> <div id="navigation"> <?php include_once('includes/admin_nav.inc.php'); ?> </div> <div id="content"> <h1>Add </h1> <br /> <!--HTML FORM--> <form method="post" action="addTournament2.php"> <table border=1 RULES=NONE FRAME=BOX> <tr> <td><font>Tournament Name</td> <td><input type="text" name="tourneyName" size="24"></td> </tr> <tr> <td><font>Game Date:</td> <td><input type="text" name="gameDate" size="24"></td> </tr> </table> <br /> <input type="submit" value="Submit" name="submit"> <INPUT TYPE=RESET VALUE="Reset Values"> </form> <br /> <?php // CONNECT TO DATABASE require_once('includes/connect.inc.php'); // QUERY TO SELECT ALL FROM PLAYER TABLE $result = mysql_query("SELECT * FROM `tournaments`"); // IF THERE IS AT LEAST 1 RECORD TO DISPLAY THE LISTING if(mysql_num_rows($result) > 0) { // START OF TABLE, HEADERS, ETC echo "<table border=1>"; echo "<tr><th>TID</th><th>Name</th><th>Date</th></tr>"; //LOOP THE DATABASE TO DISPLAY THE RECORDS while ($myrow = mysql_fetch_array($result)) { //PRINT RESULTS echo '<tr><td>'.$myrow["tourneyID"].'</td><td>'.$myrow["tourneyName"].'</td><td>'.$myrow["gameDate"].'</td></tr>'; } echo "</table>\n"; } else { //IF NO TABLE DATA TO DISPLAY //MESSAGE TO PRINT IF TABLE IS EMPTY echo "Sorry, no records were found!"; } //END ELSE STATEMENT //IF RECORDS IS ADDED SUCCESSFULLY OR NOT THE FOLLOWING MESSAGE WILL PRINT if ($success==0) { echo'There was an error. No record was added. Please try again.'; } if ($success==1) { echo'The record has been added.'; } ?> </body> </html>
  18. I tried that and still cannot get the stats table in. It gives me the 1064 error re: update/delete cascade. I got the tourneyPlayers table to go in.... here is how i changed it. I took out indexing and re-worded FK. I don't have update/delete on cascade which might cause a problem. CREATE TABLE `tourneyPlayers` ( `tourneyPlayerID` tinyint(3) unsigned NOT NULL auto_increment, `FK_playerID` tinyint(3) unsigned default NULL, `FK_tourneyID` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`tourneyPlayerID`), KEY `FK_playerID` (`FK_playerID`), KEY `FK_tourneyID` (`FK_tourneyID`) ) ENGINE=InnoDB; Any other thoughts on the stats?
  19. I have 4 create table statements that I am having difficulty with. 2 of the 4 have been entered in command line into my mysql database. I am trying to trouble shoot the reason the other 2 won't go in w/out errors. Per the Forum's Request....here is my stuff: MySQL server version -- 5.1 any errors that MySQL returns to the client [from mysql_error()]: When I enter the stats create table I get this error: ERROR 1005 (HY000): Can't create table 'baseball.stats' (errno: 150) When I enter the tourneyPlayers create table I get this error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INDEX (tourneyPlayerID, FK_playerID) FOREIGN KEY (FK_playerID) REFERENCES player' at line 6 the table structure & column indexes of the relevant tables [via SHOW CREATE TABLE is preferred]: My 4 Create Table Statements (first 2 are ok; 2nd two won't go into mysql): CREATE TABLE player ( playerID TINYINT (3) UNSIGNED NOT NULL AUTO_INCREMENT, userName VARCHAR (65) NOT NULL, password VARCHAR (65) NOT NULL, playerFN VARCHAR (48) NOT NULL, playerLN VARCHAR (48) NOT NULL, jerseyNum TINYINT (3) NOT NULL, contactName VARCHAR (48) NOT NULL, contactNumber VARCHAR (10) NOT NULL, position VARCHAR (100) NOT NULL, bats ENUM(’L’,’R’,’B’) NOT NULL, PRIMARY KEY (playerID) ) ENGINE=InnoDB; CREATE TABLE tournaments ( tourneyID TINYINT (3) UNSIGNED NOT NULL AUTO_INCREMENT, tourneyName VARCHAR(30) NOT NULL, gameDate date NOT NULL, PRIMARY KEY (tourneyID) ) ENGINE=InnoDB; CREATE TABLE stats ( statID TINYINT (3) UNSIGNED NOT NULL AUTO_INCREMENT, FK_playerID TINYINT (3) NOT NULL, atBats TINYINT (4) UNSIGNED NOT NULL , hits SMALLINT (4) UNSIGNED NOT NULL , walks SMALLINT (4) UNSIGNED NOT NULL , RBI SMALLINT (4) UNSIGNED NOT NULL , strkOuts SMALLINT (4) UNSIGNED NOT NULL , singles SMALLINT (4) UNSIGNED NOT NULL , doubles SMALLINT (4) UNSIGNED NOT NULL , triples SMALLINT (4) UNSIGNED NOT NULL , homeRuns SMALLINT (4) UNSIGNED NOT NULL , runsScrd SMALLINT (4) UNSIGNED NOT NULL, fieldersCh SMALLINT (4) UNSIGNED NOT NULL , PRIMARY KEY (statID), INDEX (statID, FK_playerID), FOREIGN KEY (FK_playerID) REFERENCES player(playerID) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE = InnoDB; CREATE TABLE tourneyPlayers ( tourneyPlayerID TINYINT (3) UNSIGNED NOT NULL AUTO_INCREMENT, FK_playerID TINYINT(3) unsigned NOT NULL, FK_tourneyID TINYINT(3) unsigned NOT NULL, PRIMARY KEY (tourneyPlayerID) INDEX (tourneyPlayerID, FK_playerID) FOREIGN KEY (FK_playerID) REFERENCES player (playerID) ON UPDATE CASCADE ON DELETE CASCADE, INDEX (FK_tourneyID) FOREIGN KEY (FK_tourneyID) REFERENCES tournaments (tourneyID) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB; a brief listing of the types of things you've attempted so far I have tried entering this in a number of ways and keep getting errors. I've switched some things around based on thing I've seen online an in the books. One big difference I seem to keep seeing is that some people put the PK on the line where its first written out. Others put it on the line closer to the bottom before the engine is declared. I know mine issue lies somewhere with the foreign keys but I honestly have no idea. I am also unsure of how I have my index set up? I read that you had to put an index on every field in order to do the FK, so did that also include putting it on every PK also?
  20. To add to this ongoing saga, I am also supposed to have the columns be sortable by ascending or descending order by clicking on them. I only have them in ascending sort order by a switch statement. Any idea how to make them sortable by descending as well? <?php include('includes/birdsHeader.inc.html'); require_once('includes/mysqli_connect.php'); // this variable will set the number of records to show per page: $display = 10; //determine pg # if (isset($_GET['p']) && is_numeric($_GET['p'])) { $pages = $_GET['p']; } else { // Count the number of records: $q = "SELECT COUNT(birdID) FROM birds"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { $pages = ceil ($records/$display); } else { //IF the query run is 10 records or less....... $pages = 1; //then the only page listed will be page 1 } } // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } //DETERMINE THE SORT $sort = (isset($_GET['sort'])) ? $_GET ['sort'] : 'ng'; //DETERMINE THE SORT ORDER switch ($sort) { case 'ng': $order_by = 'nameGeneral ASC'; break; case 'ns': $order_by = 'nameSpecific ASC'; break; case 'pt': $order_by = 'populationTrend ASC'; break; } // Make the query with the LIMIT clause: $q = "SELECT nameGeneral, nameSpecific, populationTrend, birdID FROM birds ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // HTML FOR THE TABLE HEADER/COLUMN NAMES/ALT COLOR: echo '<table border="3" align="center" cellspacing="5" cellpadding="5" width="50%"> <tr><td align="left"><b><a href="TestNoFuncAddSort.php?sort=ng">General Name</a></b></td><td align="left"><b><a href="TestNoFuncAddSort.php?sort=ns">Specific Name</a></b></td><td align="left"><b><a href="TestNoFuncAddSort.php?sort=pt">Population Trend</a></b></td></tr>'; // Fetch and print all the records... $bg = '#eeeeee'; // Set the initial background color. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['nameGeneral'] . '</td> <td align="left">' . $row['nameSpecific'] . '</td> <td align="left">' . $row['populationTrend'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc); //THIS IS THE END OF THE HTML TABLE SET UP //Links to other pages if necc if ($pages > 1) { echo '<br /><p>'; $current_page=($start/$display) +1; //previous if ($current_page != 1) { echo '<a href="birdsPagination.php?s=' . ($start - $display) . '&p=' . $pages . '&sort' . $sort . '">Previous</a>'; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="birdsPagination.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. //NEXT if ($current_page != $pages) { echo '<a href="birdsPagination.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>'; } echo '</p>'; } //end of links include ('includes/birdsFooter.inc.html'); ?>
  21. Can anyone help? I decided to start all the way over and take out ALL functions and do the code EXACTLY as it is in the book and lo and behold there are STILL problems with the pages as links so i don't think its the functions that are the problems........... see below: <?php include('includes/birdsHeader.inc.html'); require_once('includes/mysqli_connect.php'); // this variable will set the number of records to show per page: $display = 10; //determine pg # if (isset($_GET['p']) && is_numeric($_GET['p'])) { $pages = $_GET['p']; } else { // Count the number of records: $q = "SELECT COUNT(birdID) FROM birds"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { $pages = ceil ($records/$display); } else { //IF the query run is 10 records or less....... $pages = 1; //then the only page listed will be page 1 } } // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Make the query with the LIMIT clause: $q = "SELECT nameGeneral, nameSpecific, populationTrend FROM birds ORDER BY nameGeneral LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // HTML FOR THE TABLE HEADER/COLUMN NAMES/ALT COLOR: echo '<table border="3" align="center" cellspacing="5" cellpadding="5" width="50%"> <tr><td align="left"><b>General Name</b></td><td align="left"><b>Specific Name</b></td><td align="left"><b>Population Trend</b></td></tr>'; // Fetch and print all the records... $bg = '#eeeeee'; // Set the initial background color. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['nameGeneral'] . '</td> <td align="left">' . $row['nameSpecific'] . '</td> <td align="left">' . $row['populationTrend'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc); //THIS IS THE END OF THE HTML TABLE SET UP //Links to other pages if necc if ($pages > 1) { echo '<br /><p>'; $current_page=($start/$display) +1; //previous if ($current_page != 1) { echo '<a href="birdsPagination.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a>'; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="birdsPagination.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. //NEXT if ($current_page != $pages) { echo '<a href="birdsPagination.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; } echo '</p>'; } //end of links include ('includes/birdsFooter.inc.html'); ?>
  22. I'm very sorry but I am totally lost in what you are saying here......i think this code is to get how many pages based on the number of records. If there are only enough records for 1 page then it would just show up as one page but if its more, then 2, 3, 4, etc. would show up. If it helps, I"m going to upload a screen shot of what this looks like when it runs....you can kind of get the idea of what i am trying to achieve on the end result.
  23. When I run the script, only 20 birds show up. The 31 birds SHOULD be on 4 total pages, in alphabetical order based on the query. Page 1, will have 10. Page 2 will have 10. Page 3, will have 10 and page 4 should have 1. I am only seeing 20 of the 31 birds. The "previous" link (which should take you from page 4 to page 3, 3 to 2 and so on and so forth) doesn't show up AT ALL. The next button, shows up but it will only let me go from page 1 to page 2. Then it stops. When I click on the page 3 link it seems to go back to the results from page 1. The page 4 link seems to do nothing. When you say: I'm confused by this. The main part of this assignment is making the previous, next and page number links into separate functions so they need to probably return something in order for them to work and for me to complete what my teacher was looking for. Sorry if I am asking dumb question(s).
  24. I added code tags........ Pagination File: <?php include('includes/birdsHeader.inc.html'); require_once('includes/mysqli_connect.php'); include('dbFunctions.inc.php'); //Connect to the db $dbc = openDB(); //$currentPage = 'dbFunctions.inc.php'; // this variable will set the number of records to show per page: $display = 10; //DETERMINE HOW MANY PAGES THERE ARE $pages = determineNumberOfPages ($dbc, $display); echo "pages: $pages<br />"; // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Make the query: $q = "SELECT nameGeneral, nameSpecific, populationTrend FROM birds ORDER BY nameGeneral LIMIT $start, $display;"; $r = @mysqli_query ($dbc, $q); // Table header: echo '<table border="1" align="center" cellspacing="0" cellpadding="5" width="75%"> <tr><td align="left"><b>General</b></td><td align="left"><b>Specific</b></td><td align="left"><b>Population Trend</b></td></tr>'; // Fetch and print all the records.... $bg = '#eeeeee'; // Set the initial background color. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. //rid ugly empty table cell display if ($row['populationTrend'] == "") { $row['populationTrend'] = " "; } echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['nameGeneral'] . '</td> <td align="left">' . $row['nameSpecific'] . '</td> <td align="left">' . $row['populationTrend'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc); echo $pages; // Make the links to other pages, if necessary. if ($pages > 1) { echo "start: $start display: $display<br />"; // Add some spacing and start a paragraph: echo '<br /><p>'; // Determine what page the script is on: $current_page = ($start/$display) + 1; echo $current_page . "<br>"; //Call Previous Button Function $prev = previousButton ($current_page, $display, $pages); //Call the function to create the number of pages $makePage = makeNumberOfPages ($current_page, $thisPage, $pages); //Call Next Button Function $next = nextButton ($current_page, $display, $pages); echo '</p>'; // Close the paragraph. include ('includes/birdsFooter.inc.html'); } // End of links section. ?> Functions File: <?php //Function to Open MySQL & Db function openDB() { DEFINE('DB_USER', 'root'); DEFINE('DB_PASSWORD', ''); DEFINE('DB_HOST', 'localhost'); DEFINE('DB_NAME', 'birds_db'); $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR exit ('Could not connect to MySQL: ' . mysqli_connect_error()); return $dbc; } //end of function //Determine how many pages there are... function determineNumberOfPages($dbc, $display) { if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined. $pages = $_GET['p']; } else { // Need to determine. // Count the number of records: $q = "SELECT COUNT(birdID) FROM birds"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } return $pages; } //end of function //Function to make each query result listing have a page number: function makeNumberOfPages ($current_page, $thisPage, $pages) { // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="birdsPagination.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. } //end of function //Function for the Previous Button (to go back); If it's not the first page, make a Previous button: function previousButton ($current_page, $display, $pages) { if ($pages >1) { echo '<br /> <p>'; $current_page=($start/$display) +1; if ($current_page != 1) { echo '<a href="birdsPagination.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a>'; } } } //end of function //Function for the next button, if multiple pages exist; If it's not the last page, make a Next button: function nextButton ($current_page, $display, $pages) { if ($current_page != $pages) { echo '<a href="birdsPagination.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; } } //end of function ?>
×
×
  • 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.