Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. @mjdamato, should have used $player instead of $key when outputting the player information. It works really well. Thank you.
  2. @mjdamato What you produced works pretty well. It doesn't output the player information though. The structure shows up, as best as I can tell exactly how I want it. @voip03 Do you mean to determine the structure? Certainly you can to determine how it actually looks, whether you want to use a table or list format. In this instance, I just need a list.
  3. Sorry, sort of took it for granted. Table "schools", just matches the User, which is a coach, to his team/players. All the information being output is from "players", one status per player. $sql = "SELECT * FROM players as p INNER JOIN schools as s WHERE p.tid = s.id ORDER BY status, playerLast"; $results = mysql_query($sql);
  4. I'm trying to output this: Status Player Player Player Status Player Player Player Status Player Player I tried this, but it didn't work: while($players = mysql_fetch_assoc($results)) { foreach ($players as $player=>$status){ echo '<div>' . $player['status'] . '</div>'; foreach ($status as $key) { echo $key['playerFirst'] . ' ' . $key['playerLast'] . ', '. $key['year'] . '<br>'; } } } I guess I'm trying to find a more efficient way of doing this rather than if/elseif for each one. Right now, there are only four groupings, but in the future there could be as many 406.
  5. I don't work with JS at all--php a lot though--but I'm hoping some small input can help me see the logic in it. This is part of another problem I had, which has led me to the JS portion of it. The below code allows the User to submit a message and have it show up on the screen in real time, without a refresh. The middle part of it is interaction with a database. Here is the demo: http://demos.9lessons.info/update_delete.php My issue is I have a form where I'd like it to include the person's first and last name (actually more than that). In searching for the answer here and the internet in general, I find examples of form submission, serialized data, etc, but nothing that I can make enough sense to fit it into the below code. My main interest is the real time nature of it. Otherwise, I can easily set up my form to Insert, present a new form, and show an updated list to the User via a refresh after submitting data. Basically, it's coaches creating a roster online. How do I go about adding the fields I need to include? <script type="text/javascript"> $(function() { $(".comment_button").click(function() { var element = $(this); var boxval = $("#content").val(); var dataString = 'content='+ boxval; if(boxval=='') { alert("Please Enter Some Text"); } else { $("#flash").show(); $("#flash").fadeIn(400).html('<img src="ajax.gif" align="absmiddle"> <span class="loading">Loading Update...</span>'); $.ajax({ type: "POST", url: "/live_update/update_data.php", data: dataString, cache: false, success: function(html){ $("ol#update").prepend(html); $("ol#update li:first").slideDown("slow"); document.getElementById('content').value=''; $("#flash").hide(); } }); } return false; }); $('.delete_update').live("click",function() { var ID = $(this).attr("id"); var dataString = 'msg_id='+ ID; if(confirm("Sure you want to delete this update? There is NO undo!")) { $.ajax({ type: "POST", url: "/live_update/delete_data.php", data: dataString, cache: false, success: function(html){ $(".bar"+ID).slideUp('slow', function() {$(this).remove();}); } }); } return false; }); }); </script>
  6. I've sort of backed my way into this question on two topics now. My other problem has led me to consider the javascript linked above. I got it to work on my site, but in trying to expand it, it just shows the one field. Here is the code in the link above: <script type="text/javascript"> $(function() { $(".comment_button").click(function() { var element = $(this); var boxval = $("#content").val(); var dataString = 'content='+ boxval; if(boxval=='') { alert("Please Enter Some Text"); } else { $("#flash").show(); $("#flash").fadeIn(400).html('<img src="ajax.gif" align="absmiddle"> <span class="loading">Loading Update...</span>'); $.ajax({ type: "POST", url: "/live_update/update_data.php", data: dataString, cache: false, success: function(html){ $("ol#update").prepend(html); $("ol#update li:first").slideDown("slow"); document.getElementById('content').value=''; $("#flash").hide(); } }); } return false; }); $('.delete_update').live("click",function() { var ID = $(this).attr("id"); var dataString = 'msg_id='+ ID; if(confirm("Sure you want to delete this update? There is NO undo!")) { $.ajax({ type: "POST", url: "/live_update/delete_data.php", data: dataString, cache: false, success: function(html){ $(".bar"+ID).slideUp('slow', function() {$(this).remove();}); } }); } return false; }); }); </script> I have that in the same file as the form. Would the JS have any effect on what is being passed from the form to the file that processes the data and Inserts into the database? It only passes the Content field to my database. What would I need to change?
  7. Maybe I should clarify. The JS is on the file with the form. From the form to the update_data.php, it appears to only be passing along the Content field. Would the JS have any effect on that?
  8. Ok...I got rid of the errors. There were a few, another comma and two bad variables. HOWEVER, the only value being passed is the one for "content". There is another aspect of this that maybe I didn't understand. In using this code for this site, I have some javascript going on that is suppose to show the submission on the page in real time, without having to refresh. It's working with the...you guessed it...the "content" field. I assumed the JS just created the effect then passed the User to the code that processes the data. Do I have to reflect all the fields I need passed in the JS??? (I don't work with JS at all. It was a open source code.) <script type="text/javascript"> $(function() { $(".comment_button").click(function() { var element = $(this); var boxval = $("#content").val(); var dataString = 'content='+ boxval; if(boxval=='') { alert("Please Enter Some Text"); } else { $("#flash").show(); $("#flash").fadeIn(400).html('<img src="ajax.gif" align="absmiddle"> <span class="loading">Loading Update...</span>'); $.ajax({ type: "POST", url: "/live_update/update_data.php", data: dataString, cache: false, success: function(html){ $("ol#update").prepend(html); $("ol#update li:first").slideDown("slow"); document.getElementById('content').value=''; $("#flash").hide(); } }); } return false; }); $('.delete_update').live("click",function() { var ID = $(this).attr("id"); var dataString = 'msg_id='+ ID; if(confirm("Sure you want to delete this update? There is NO undo!")) { $.ajax({ type: "POST", url: "/live_update/delete_data.php", data: dataString, cache: false, success: function(html){ $(".bar"+ID).slideUp('slow', function() {$(this).remove();}); } }); } return false; }); }); </script>
  9. Status is my last field. Where should a comma go?
  10. Ok...I guess, but it's working quite well on another site, which is currently in the part of the year when it's most used. I've had additions made to it today. The other issue is it's passing the value for "content" but not the other fields.
  11. I have a form that is passing the User to following code. The code below is just ported from another site that I created, which works extremely well. I've had to change the datatable, database connection and some of the variables for this site, but it's otherwise the same. I've triple checked the variables. The datatable is accurate. It doesn't appear to be passing variable from the Form with the exception of "content", and I'm getting the following error: What am I missing? <?php include('db.php'); $playerFirst = $_POST['playerFirst']; $playerLast = $_POST['playerLast']; $feet = $_POST['feet']; $inches = $_POST['inches']; $year = $_POST['year']; $position = $_POST['position']; $content = $_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']; //if(isSet($_POST['playerFirst']['playerLast']['feet']['inches']['year']['status'])) //{ /* search for existing row */ $sql = "SELECT msg_id FROM players WHERE playerFirst='".mysql_real_escape_string($playerFirst)."' AND playerLast='".mysql_real_escape_string($playerLast)."'"; 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 feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', content='".$content."', 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)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', content='".$content."', 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); } }
  12. That was my next question above. Basically I just use If statements for each required field?
  13. I get that, but I have a specific user base, all professionals in the same field, which I know them all by name. In a 12 field form, I just need to make sure they answer those in the least. Four of them are drop downs.
  14. I guess I'm not grasping what you're saying. All I care about is someone not trying to forward an empty field. I'm dealing with a specific User base, coaches. They aren't going to be the type that tries to get cute with entries, and I won't have to worry about checking for specific characters. They will all type in the names, but once they get far enough down their roster, they might try to cut some corners by not submitting height, grade, etc. If they leave a required field blank, I'd have it say to make sure all required fields are filled. If all are filled, the form will make see if the name is already entered. If so, it will treat the submission as an update. If not it will insert a new row of data. I have all of that done except checking for required fields.
  15. "empty" I get. Would I use if...elseif...elseif...etc to cover each entry?
  16. Wait...maybe I screwed something up. I just want to make sure Users fill out those fields before moving on. Most would just fill in the name and try to move on. I have a Live Update set up, so it's showing submissions in real time. I'm just trying to make some fields required. Pikachu, what you have seems to be just a bit more complicated than I really need. Can I check for required fields in the way I posted above?
  17. If I wanted to make multiple fields required before letting a User move past the field is this the proper way to do it? if(isSet($_POST['playerFirst']['playerLast']['feet']['inches']['year']['status'])) { ## Something } else { ## Something else }
  18. Ok...figured out the (msg) part is table column and a function of the INSERT tag. (I thought "content" was the column. It's not.) Core functionality is working for me. Now I had to add the fields I need and make it able to match the coach's name.
  19. Question about this query: What does the (msg) do? How is it used? $content=$_POST['comment']; mysql_query("insert into players(msg) values ('$comment')"); $sql_in= mysql_query("SELECT msg,msg_id FROM players order by msg_id desc"); $r=mysql_fetch_array($sql_in); $msg=$r['msg']; $msg_id=$r['msg_id'];
  20. You guys posted those previous two response while I was responding to AyKay. Good stuff. I'll take a look at it and update here as I go along. I'm sure I'll need help.
  21. I do have some jQuery on my site (tabbed UI) that I manipulate a little. Is there something specific I should be looking for? Example, I know to go to the UI part to find UI solutions. Almost like their plugins. Is there something like that? Is there something called Live Update? THAT would be nice. : ) I hate to say it, my brain isn't good with starting from scratch to learn code. In HS (grad 1988), I could start decent programs from scratch in Fortran, but I went away from coding in college and didn't start to pick it back up until about 2003. I'm able to find the logic in a lot of what I see that applies to my problem and tweak it, but it's hard to learn from scratch when just about everything I do has to be while hitting the ground running. Luckily, most of these projects for me.
  22. I'm not looking for code, mostly just some direction, but I'm sure I'll be back as I try to shape the code. Also, I know very little about coding jQuery, Ajax, etc. Here is what I'm looking for: Basketball coach enters a Page that only he (or admin) can see. (I have that part figured out.) Once there, he has a form to fill out with a player's name and other information. I'd rather there not be 12 rows of empty cells. (Coaches will view that as work) I'd rather not have the Page reload on each "Add", but that would be the lesser of two evils. Is there a way to keep a persistent connection so when a coach hits Add, the player gets added to the database, a new empty form shows up, and the player's information shows up below on a roster?
  23. I have a data table inside my WP database that has coachFirst, coachLast, email, school as columns. I'm trying to create a page that acknowledges the User (that part works). From there it matches the first and last names in my data table then echos the school where they coach. It's the latter I can't get to work. Example, for me it looks like It show the name of the team I coach below that. It doesn't...of course. Here is the code/query I'm using: $current_user = wp_get_current_user(); $current_first = $current_user->user_firstname; $current_last = $current_user->user_lastname; echo 'Username: ' . $current_user->user_login . '<br />'; echo $current_first . ' ' . $current_last; $query = "SELECT * FROM schools WHERE coachFirst='$current_first' AND coachLast='$current_last'"; $result = mysql_query ($query); while ($result) { echo $result['school']; }
  24. I appreciate the link, but your code doesn't really help me. It just changes the output when I get an error vs. when the query produces nothing. In this instance it's likely both, and I'm really trying to work my way through Joins. What I've read on them doesn't give me much to go on, and that includes searching here and reading MySQL.
  25. Ooops...sorry. I had figured that out but didn't follow up. Thank you for your help.
×
×
  • 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.