Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. I figured a little more out: $termID = "SELECT LAST_INSERT_ID()"; It at least doesn't throw an error. It input a zero though.
  2. I have built on this, as I mentioned above (thinking it would be easier), trying to write a third table. In table wp_term_taxonomy, a new row is created when wp_terms adds one. It tells what kind of "term" was added. For my purposes, it's always "post-tag", and it links the id from wp_term, which always matches the id in wp_term_taxonomy. I need to duplicate that term_id as a I add a row. wp_term_taxonomy columns: (Only 1294 is what I inserted, but the previous rows shows you what it should be) Here is the code I'm using (built off of what we have above). Trying to use lastInsertID(). Right now, we're just looking at $stmt3 variables ($taxonomy, $termID) $team = $_POST['school']; $level = $_POST['level']; $season = $_POST['season']; // This uploads it into the Rosters table $stmt = $con->prepare("INSERT INTO a_rosters(team, uniform, nameFirst, nameLast, feet, inches, level, season, grade, position) VALUES (?,?,?,?,?,?,?,?,?,?)"); $stmt->bind_param('ssssssssss', $team, $uniform, $fname, $lname, $feet, $inches, $level, $season, $grade, $position); $stmt2 = $con->prepare("INSERT INTO wp_terms(name, slug) VALUES (?,?)"); $stmt2->bind_param('ss', $name, $slug); $stmt3 = $con->prepare("INSERT INTO wp_term_taxonomy(taxonomy,term_id) VALUE (?,?)"); $stmt3->bind_param('ss',$taxonomy,$termID); foreach ($_POST['uniform'] as $k => $uniform) { $fname = $_POST['nameFirst'][$k]; $lname = $_POST['nameLast'][$k]; $feet = $_POST['feet'][$k]; $inches = $_POST['inches'][$k]; $grade = $_POST['grade'][$k]; $position = $_POST['position'][$k]; $name = "$fname $lname"; $slug = strtolower("$fname-$lname"); $taxonomy = "post_tag"; $termID = $con->lastInsertID(); <---- line 35 $stmt->execute(); $stmt2->execute(); $stmt3->execute(); Before I worried about $termID, I started with just the $taxonomy part, and it added "post_tag" to row 1294. I hadn't defined term_id yet, so it added a zero. I haven't been able get the $termID to recognize the lastInsertID(). I've seen various 'solutions' and tried 3 or 4 of them. Mostly I get this error... Part of me also wonders, is lastInsertID() getting the id of the current row or the previous row, and would I need to somehow add a +1 to the mix.
  3. I used the top version, very simple to understand...after seeing it of course.
  4. Interesting you led with combining it with the initial query. While searching for ideas on how a query would look, I considered making it all one query. Many of the instances said while it made sense to try it just as easy to use a separate query. Which do you think is better? 1-12 rows at a time, likely not much of a resource / time difference. In the first one, wouldn't I still need the [$k] for the array? EDIT: I added this, and it worked. Why $name and $slug twice in the second example? One for each concat?
  5. So I don't concat in the insert? Does the concat take place in the foreach loop?
  6. It's already created. It's what WordPress uses. I've piggy backed on the tag.php page to put my own content on it, pulling the slug off the URL. I'm just trying to update the wp_terms table as names get entered into the site. (I'll update the wp_terms_taxonomy table as well in the process, but that's take care of.)
  7. I have name and slug in the insert query. Not sure what you mean by it's not in there. Never dealt with PDO syntax before this topic, nor dealt with bind_param. I was trying to apply your earlier code to this.
  8. It's so I can create WordPress tags as I go. I'm using the tag template to auto-generate player profiles. I'm calling a function toward the top of tag.php (generic name) to put my custom information on there. Under that will be the normal content a tag.php would present on a WP site. Doing this will keep me from having to add tags later or update the table periodically. This is much easier than creating my own profile page, then digging into WP templating and styling it the way I want it. I've had this way for 5-6 years, but now with coaches entering so many extra players, I'm trying to take care of it all at once. So I'm not creating anything, just inserting to what is already there.
  9. Memory refresh: I'm this code handles the User typing in a roster of players, using a form with repeated fields. It would be any number of players from 1 to 12. Apply the code from above, using input from the same form, I want a separate INSERT with just the first and last name into an additional data table as 'name' and 'slug'. $stmt = $con->prepare("INSERT INTO wp_terms(concat(nameFirst,' ',nameLast) as name, concat(lower(nameFirst),'-',lower(nameLast)) as slug) VALUES (?,?)"); $stmt->bind_param('ss', $name, $slug); foreach ($_POST['name'] as $k => $name) { $slug = $_POST['slug'][$k]; $stmt->execute(); } This is the error I received:
  10. It did work. Thank you. Always appreciate the help I get.
  11. I changed the TYPE for feet and inches to VARCHAR. I think helped some, but it's also preceding the number with quotation marks. I opened the file in a text editor, and those fields are wrapped with " ". So in position = "PG" @height = "6'4"" <= extra set of double quotes at the end So I'd need to reshape the delimiters. For inches, we have: inches = substring_index(substring_index(@height, '\"', 1), '\'', -1) Would that be a 2 in this instance?
  12. I increased the field lengths for position, feet and inches. Still getting 0's in feet and inches, but position looks like this now... So it's showing the whole position, but where the were multiple positions listed (I just want their primary position), it shows the quotation marks on the left.
  13. Keep what a secret? Here is the file. I forgot to add it. I deleted the columns I'm not using. Here is what it looks like after loaded into the database: Database structure:
  14. Ooops...I've been taking them out as I've posted them because I'm skipping over them in the CSV. Skipping @email, @cell, @role, @video, @weight It's lined up fine, other than the substrings not producing
  15. Interesting too (at least to me), I changed position to @position then added this line: position = substring_index(@position, ',', 1), It should produce entries like PG, SG, SF. Instead, it's producing "P, "S, "S, whereas the rows w/o the , in position produce what's intended.
  16. Disregard the previous post. I had misaligned columns. However, it's still showing 0 in feet and inches... ...with the current query $query = " LOAD DATA LOCAL INFILE '$tmp' INTO TABLE a_rosters FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 Lines (grade,uniform,nameFirst,nameLast,position,@height) SET team = '" .$team . "', level = '" .$level. "', feet = substring_index(@height, '\'', 1), inches = substring_index(substring_index(@height, '\"', 1), '\'', -1) ";
  17. It didn't added the feet or inches columns in the database. They just show up as 0.
  18. Yep...changing it to a CSV file worked. Is there an easy to handle an xlsx file, or will I need to have my Users (coaches) export to CSV? (Not sure what they're exporting from does that just yet. My test User is checking.) It would be easier for my users if I could handle an xlsx file. (I'll search for that after I hit submit.) EDIT: The answer seems to be that I will need to convert it to a CSV file. Agree?
  19. Current code: $filename = $_FILES['fileToUpload']['name']; $tmp = $_FILES["fileToUpload"]["tmp_name"]; $team = $_POST['team']; if(isset($_POST["submit"])) { echo $target_file . '<br>Roster Sent'; echo '<br>' .$filename; echo '<br>' .$tmp; $uploadOk = 0; } $query = " LOAD DATA LOCAL INFILE '$tmp' INTO TABLE a_rosters FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 Lines (uniform,nameFirst,nameLast,position,@feet,@inches) SET team = '" .$team . "', feet = substring_index(@feet, '\'', 1) * 12 , inches = substring_index(substring_index(@inches, '\"', 1), '\'', -1) "; $results = mysqli_query($con,$query); echo mysqli_error($con);
  20. I see your EDIT above. I omitted the second substring_index of line 30. I copied what you wrote above, changing @height to @feet and @inches. Still throwing this error: Parse error: syntax error, unexpected '', 1), '' (T_CONSTANT_ENCAPSED_STRING) in /home2/csi/public_html/wp-content/plugins/csi_stats/csi_roster_upload_process.php on line 30 $query = " LOAD DATA LOCAL INFILE '$tmp' INTO TABLE a_rosters FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 Lines (uniform,nameFirst,nameLast,@email,@cell,position,@role,@video,@feet,@inches,@weight) SET team = '" .$team . "', feet = substring_index(@feet, '\'', 1) * 12 , inches = substring_index(substring_index(@inches, '"', 1), '\'', -1) <= line 30 "; I added the / before the " in line 30. No more errors, but it's not loading the data. Would it have to do with the file being an .xlsx file vs. a .csv?
  21. First I was getting this error: So I added a \ before the " include("/pathway/to/con.php"); $filename = $_FILES['fileToUpload']['name']; $tmp = $_FILES["fileToUpload"]["tmp_name"]; $team = $_POST['team']; if(isset($_POST["submit"])) { echo $target_file . '<br>Roster Sent'; echo '<br>' .$filename; echo '<br>' .$tmp; $uploadOk = 0; } $query = " LOAD DATA LOCAL INFILE '$tmp' INTO TABLE a_rosters FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 Lines (uniform,nameFirst,nameLast,position,@feet,@inches) SET team = '" .$team . "', feet = substring_index(@feet, '\'', 1), inches = substring_index(@inches, '\"', 1), '\'', -1) // <= This is where that error was "; $results = mysqli_query($con,$query); echo mysqli_error($con); It produced my echos, but it also threw this error: (Same line, really)
  22. SET feet = substring_index(@feet, '\'', 1), inches = substring_index(@inches, '"', 1), '\'', -1) Trying that when I get back to my desk.
  23. Can't I also set the substring_index to find @feet then @inches? SET feet = substring_index(@feet, '\'', 1) SET inches = substring_index(@inches, '"', 1), '\'', -1)
  24. Height isn't roster dependent, and most of the players that will be entered by the coaches will not be in the database, so we'll need to include their height regardless. I have key indexes set up not to allow duplicates. Height will be imported here as #'#", but the my database is set up in two columns, feet and inches for over 800 rows. It's also easier for me to create exports for others with different formats, most notably those who want exports in #-# as is common in the US. I know how to get data out how I need it. (At least as it's currently situated.) I've just come across a way that I don't know how to get the data in as I want it.
×
×
  • 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.