Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. Adam, that was the error which was produced.
  2. I've been looking at ORDER BY examples, and what I've found so far tells me to do it that way. I'll keep looking.
  3. I'm getting an invalid argument error for my While loop. I can't figure out why. $sql="SELECT * FROM schools ORDER BY class DESC,sectional ASC,team ASC"; $results = mysql_query($sql); while ($team = mysql_fetch_assoc($results)) { echo $team['school'] . '<br>'; } Here is the error:
  4. It appears I had the wrong syntax. Thanks. That worked.
  5. I'm using Sequel Pro on Mac. My query is: SELECT * FROM fallLeague10 WHERE confirm!='y' I have three values: y m NULL I'm trying to get the rows that aren't y. Only the rows of m show up. I can't get the NULL rows to show up.
  6. Is there another way I should do it? I guess if you can find it, get to it, have the same name as the coach with the same user id...go for it.
  7. I did it to eliminate special characters from names, such as apostrophes and hyphens from names. They don't play nicely with WordPress' taxonomy.
  8. Maybe a similar issue dealing with empty fields. In the Update query, can I use a if(!empty) as part of the query for each field? I want the User/coaches to be able to update their mistake, and the Update query allows the coach to do that if they match the player's first name and last. It was originally set up to make sure the same player isn't entered multiple times, but it also gives the coach a chance to update any information.
  9. Ok...this goes into the "duh" column. I can just use !empty. : ) Sometimes posting about it here helps me think through it. if (!empty($comments['msg'])) { echo '<span class="roster_player_name">' . $comments['playerFirst'] . ' ' . $comments['playerLast'] . ': </span>'; echo $comments['msg'] . '<br><br>'; }
  10. The only field I need left NULL is the comments (form)/msg (query) field. If it's empty, the query just needs to bypass it because submitting it as blank just leaves the field in my data table blank.
  11. I realize I might not have been clear. I want the form to recognize that field is blank, and if it is do nothing. I also want to make sure "do nothing" leaves that field as (NULL)
  12. @nighslyr, the problem with that is it's part of a bigger form and not a required field. In fact, I would say more times than not, it would be left blank. It's coaches entering roster information, and they would likely put in some comments about top players or players needing to take on a bigger role. In the comment section of the output, I only want to echo the names that have comments...and the comments. It's the $msg variable below. I should have posted the code initially. My apologies. The rest of this code works extremely well as intended, and I use its structure on two sites. $playerFirst = $_POST['playerFirst']; $playerLast = $_POST['playerLast']; $tid = $_POST['tid']; $school = $_POST['school']; $feet = $_POST['feet']; $inches = $_POST['inches']; $year = $_POST['year']; $position = $_POST['position']; $msg = $_POST['content']; $ppg = $_POST['ppg']; $rpg = $_POST['rpg']; $apg = $_POST['apg']; $spg = $_POST['spg']; $bpg = $_POST['bpg']; $fgp = $_POST['fgp']; $ftp = $_POST['ftp']; $status = $_POST['status']; /* search for existing row */ $sql = "SELECT msg_id FROM players as p INNER JOIN schools as s WHERE p.playerFirst='".mysql_real_escape_string($playerFirst)."' AND p.playerLast='".mysql_real_escape_string($playerLast)."' AND p.tid=$tid"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); /* update existing row */ $sql = "UPDATE players SET pschool='" . $school . "', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."', year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', msg='".mysql_real_escape_string($msg)."', ppg='".$ppg."', rpg='".$rpg."', apg='".$apg."', spg='".$spg."', bpg='".$bpg."', fgp='".$fgp."', ftp='".$ftp."', status='".$status."' WHERE msg_id='".$row['msg_id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } else { /* insert new row */ $sql = "INSERT INTO players SET playerFirst='".mysql_real_escape_string($playerFirst)."', playerLast='".mysql_real_escape_string($playerLast)."', tid='". $tid ."', pschool='" . $school . "', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."', year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', msg='".mysql_real_escape_string($msg)."', ppg='".$ppg."', rpg='".$rpg."', apg='".$apg."', spg='".$spg."', bpg='".$bpg."', fgp='".$fgp."', ftp='".$ftp."', status='".$status."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } }
  13. I have one field which is set up as a Text field in my database. What I'm wanting is if the field is blank in the form to just leave the field alone in the database. I need it to be NULL. OR...is there a way to query a database to recognize a field is blank?
  14. Ignore...screwed up.
  15. Here's the code that finally worked: $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE s.coachFirst='".$current_first."' AND s.coachLast='".$current_last."' AND s.id = p.tid ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="roster_team_info">' . $current_first . ' ' . $current_last . ' <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; echo '<div class="roster_player_list">'; mysql_data_seek($results,0); $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; // echo "<div><b>{$currentStatus}</b></div>\n"; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; } I added the mysql_data_seek in there. It works nicely now. Is that the most efficient way to handle multiple queries on a file? I have other projects that have multiple queries, to the point where they are pretty daunting to change as I adapt them to my needs. Should I make the conversion to this? I'm even talking about the help I got on another topic dealing with While / IF nested loop too.
  16. This is the entire code now: $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE s.coachFirst='".$current_first."' AND s.coachLast='".$current_last."' AND s.id = p.tid ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="roster_team_info">' . $current_first . ' ' . $current_last . ' <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; echo '<div class="roster_player_list">'; $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; // echo "<div><b>{$currentStatus}</b></div>\n"; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; }
  17. Not sure mysql_result is working. I put... $team = mysql_result($results, 0); I'm not even sure how the result I got came up. It should only get one result, so the 0 is the offset value, which means it starts at the first row. I think I understand that correctly. JWR Bloom 2 Coach 2 2 Sectional: 2 Class: 2A
  18. mysql_affected_rows doesn't work. : ) Is there another function that will accomplish what I want, or do I have a separate query?
  19. Oh...I tried a number of ways to output what's just below it in DIV roster_team_info, including just using the $result variable. I did wonder about that, thinking of the description of that fetch, that it moves the pointer ahead. How do I go about getting my result? Separate query or something like affected rows? The information in that DIV just comes from the schools data table. Oddly enough, that might answer my question in another post.
  20. No. That's just there to show Returning Starters is value 1.
  21. I'm not even sure how to explain it. I'm linking a team's roster to its coach. Now I'm getting a weird offset issue when I output the roster. It has something to do with the STATUS. Down below DIV class="roster_player_list", my Status values are 1, 2, 3, or 4, and each is then assigned a word value. My output should look like this (without the arrow and number) : Returning Starter <---- 1 # # # Key Returner <--- 2 # # Varsity Newcomer <--- 3 # # # Key Freshmen <--- 4 # The last "1" (Returning Starter) disappears from my list on both of my test accounts. I should have four Returning Starters instead of three. I've changed a player's status from a 2 to a 1, and the list changed. That player disappeared, the other appeared. $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE s.coachFirst='".$current_first."' AND s.coachLast='".$current_last."' AND s.id = p.tid ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="roster_team_info">' . $current_first . ' ' . $current_last . ' <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; echo '<div class="roster_player_list">'; $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; }
  22. Awesome. Thanks. I have another one down there, dealing with the same code, different issue.
  23. Basically what I'm getting with that is the WHILE loop picks up there is no match, but the IF doesn't. So it's not showing the contact_form DIV, but it is show the roster DIV. It's probably something grossly simple that I'm missing or just basically goes over my head.
  24. Man, I'm having a rough week with questions--if you're following at home. Basically matching a Coach's first and last name to another table, which if matched will yield information about that coach's team. // or get user by username $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; $current_id = $current_user->ID; echo '<div class="contact_form">'; echo $current_first . ' ' . $current_last .' :: '; $query = "SELECT * FROM schools WHERE coachFirst='".$current_first."' AND coachLast='".$current_last."'"; $result = mysql_query ($query); if(!$result) { echo 'There is not a match for your name.'; } else { while($school= mysql_fetch_array($result)) { echo $school['school'] . ' ' . $school['id']; include(ABSPATH ."wp-content/plugins/my-team/form.php"); } echo '</div>'; echo '<div class="roster">'; include(ABSPATH ."wp-content/plugins/my-team/roster.php"); echo '</div>'; }
  25. The whole code is below, followed by the part that isn't producing. It all works extremely well until the last part, and I have two instances of setting a variable to mysql_fetch_assoc that work. Not sure why the third attempt doesn't. I'm just trying to have a separate area that outputs 'msg'. $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE p.tid = s.id ORDER BY status, playerLast"; $results = mysql_query($sql); echo '<div class="roster">'; $team = mysql_fetch_assoc($results); echo '<div class="team_info"> <div class="school">' . $team['school'] . '</div> <div class="coach">Coach ' .$team['coachFirst'] . ' ' . $team['coachLast'] .'</div> <div>Sectional: ' . $team['sectional'] . '</div> <div>Class: ' . $team['class'] . 'A</div> '; echo '</div>'; $currentStatus = false; //Flag to detect change in status while($player = mysql_fetch_assoc($results)) { if($currentStatus != $player['status']) { //Status has changed, display status header $currentStatus = $player['status']; echo '<br><b>'; if ($currentStatus == '1') {echo 'Returning Starters';} elseif ($currentStatus == '2') {echo 'Key Returners';} elseif ($currentStatus == '3') {echo 'Varsity Newcomers';} elseif ($currentStatus == '4') {echo 'Key Freshmen';} echo '</b><br>'; // echo "<div><b>{$currentStatus}</b></div>\n"; } //Display player info echo $player['playerFirst'] . ' ' . $player['playerLast'] . ', ' . $player['feet'] . '\'' . $player['inches'] . '",' . $player['position'] . ', ' . $player['year'] . ';<br>'; } //Player comments echo '<hr>'; echo '<div class="coach_comments"><span class="player_name">hello'; while($comments = mysql_fetch_assoc($results)) { echo $comments['playerFisrt'] . ' ' . $comments['playerLast'] . ': </span>' . $comments['msg']; } echo '</div>'; echo '</div>'; It's all working until what's below. All I get out of it is the "hello", which is just a test to make sure it wasn't a CSS issue.
×
×
  • 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.