Jim R
Members-
Posts
988 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Jim R
-
I'm getting an "invalid argument" error for my While loop....
Jim R replied to Jim R's topic in PHP Coding Help
Adam, that was the error which was produced. -
I'm getting an "invalid argument" error for my While loop....
Jim R replied to Jim R's topic in PHP Coding Help
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. -
It appears I had the wrong syntax. Thanks. That worked.
-
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.
-
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.
-
I did it to eliminate special characters from names, such as apostrophes and hyphens from names. They don't play nicely with WordPress' taxonomy.
-
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.
-
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>'; }
-
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.
-
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)
-
@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); } }
-
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?
-
Ignore...screwed up.
-
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.
-
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>'; }
-
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
-
mysql_affected_rows doesn't work. : ) Is there another function that will accomplish what I want, or do I have a separate query?
-
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.
-
No. That's just there to show Returning Starters is value 1.
-
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>'; }
-
Awesome. Thanks. I have another one down there, dealing with the same code, different issue.
-
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.
-
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>'; }
-
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.