Jump to content

lordterrin

Members
  • Posts

    18
  • Joined

  • Last visited

lordterrin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. holy........ crap....... This whole thing was just because I didn't have # sign in front of my DIV. Hah! I changed that around and it worked just fine! THANK you!
  2. I have the same issue (while we're on it) with this second statement: <form id="startPage" method="POST" action="getuser.php?q=<?php echo $q; ?>"> Page <?= $_SESSION['page'] ?> of <?= $totalPages ?> : <input class="button" type="submit" name="previous" value="START" onclick="this.value=<?php echo $prevLimit; ?>"> <input class="button" type="submit" name="next" value="NEXT" onclick="this.value=<?php echo $nextLimit; ?>"> </form> I created a few variables, $prevLimit, $nextLimit, and $totalPages - in order to split the results of what I pull in the SQL query that generates the table into manageable pieces. Here's the button: When the user loads the page at the start, this is set to "Page 1 of 7", meaning there are a total of 70 entries for this person, and since I'm only showing him 10 at a time, there are 7 pages. When the user clicks on START or NEXT, it WORKS - it increases the various php variables and re-populates the table with entries 10-19, then 20-29, etc. This was the best way I knew to build this functionality into my project. However, I'm suffering from the same thing as above - since getuser.php is loaded "inside" of ajaxtest.php, when they click the button, it reloads getuser.php and gets rid of the ajaxtest.php header bar that I have on the top of the page. Here's what it looks like if it helps: The top part of the image is what they see when they load ajaxtest.php, then when they select a user from the drop-down, the bottom part of the page is populated. Of course, I understand why this is not working - because of this line of code <form id="startPage" method="POST" action="getuser.php?q=<?php echo $q; ?>"> I say - when this form is activated, action getuser.php?q=John%20Doe - I just don't know how to make this work.......
  3. Thank you - both of you - for taking the time to help me out. @david- I believe I have somewhat tried what you're suggesting above... // Submit the form using AJAX. $.ajax({ type: 'POST', url: form.attr('action'), data: formData, success: function() { toastr.success('Update Successful', ''); $.get("getuser.php?q="+encodeURIComponent(pmName), function(data) { $('txtHint').html(data); }); } }); What I'm trying to say here is - upon success of this AJAX function, the database will have updated, so: get getuser.php?q=John%Doe, then: put that result back into the txtHint DIV. This doesn't work, and my understanding of why this doesn't work is because I don't know how to tell this function that 'txtHint' exists on ajaxtest.php I've read through a few posts, but I can't figure out syntactically how this second part works. I get that $('txtHint') is the name of the DIV that I want to put stuff into, but I don't understand what the .html does intrinsically, (e.g. - if this div exists on a php page, do I still use .html?) I am assuming that (data) is a reference to the line above, where I'm taking the information from $.get() and putting it into a function called (data). If my understanding of this is wrong, please tell me. I don't understand exactly what this line is doing, but I will attempt to explain my understanding of it: document.getElementById('namehere').innerHTML = ajaxobject.responseText; This code will go on my initial ajaxtest.php page. When this page initially loads, this line of code will be read, but nothing will come of it, as at that exact moment there is no data inside (responseText). Later, when I make a change and click the submit button, and my update.js file executes, and the ajax function runs, (responseText) is filled with data and is [somehow magically] returned to this document.getElementById call. @Frank - I'm somewhat clear on the difference between server-side and client-side, and what's happening where. This has only deepened my confusion though as I attempt to solve this. I've read a bit on JSON, and its similarities to XML, but I don't really understand HOW that helps me in this situation. I spent a few weeks working through this initial ajax query that I posted above, trying to understand how it works, but I am obviously still pretty new at this, and just trying to make logical sense of it.
  4. I have a page that functions like this: The user begins by loading ajaxtest.php, then using a drop-down menu, selects a user, after which a DIV on ajaxtest.php is populated with the user's selction to getuser.php?q=John%Doe Here's a visual representation of what is currently happening, along with the part I don't understand. getuser.php consists largely of a a large HTML table which interacts through PHP with my SQL database. Several of the fields in this table are editable, and after the user changes one of these fields, he can press an "update" button, which calls an AJAX script in update.js and runs update.php, which contains all my SQL queries to update the database, without the user being redirected to this update.php page. All of this is processing perfectly - the user makes some sort of edit, hits "update", and the database gets updated without any redirection or refresh. Here's what I can't figure out though. Once the user makes a change, and hits "update," the database updates, but the end user doesn't see those changes that he made. I can't just do a simple page refresh, because the action is taking place on getuser.php, but getuser.php is loaded inside of a #DIV on ajaxtest.php. If I use something like window.location.reload(), this just refreshes ajaxtest.php and puts the user back to the starting point of having to select a user. This is not what I want. I don't want to refresh ajaxtest.php, I want to "refresh" ajaxtest.php with getuser.php?q=John%Doe insidethe DIV on ajaxtest.php. It seems like this is very common - several forums have this capability, where a user has a page loaded, adds a comment, and sees that comment immediately without a full page refresh. I just don't know how to do it, and I've tried at lengths to search the web for an answer with no luck. Can someone walk me through how to do this?
  5. So I've done a bit of reading, and it seems that I may be able to assign an id inside of a <tr>, then use javascript's addEventListener to do something. There is an example of something similar here: http://jsfiddle.net/CcqU7/222/ so my code starts here: echo "<td id='PMCUpdate' style='width:70' contenteditable='true' id='PMC'>" . $row['Comments'] . " </td>"; Then in the header section, I have this: <script language="javascript1.2"> var SQLPMC = document.getElementById("PMCUpdate"), SQLPMC.getElementById("PMCUpdate").addEventListener("input", function() { alert("input event fired"); }, false); </script> Reading through this, it seems to make sense... but nothing happens. I'd like for each cell in the comments column of my table to be editable, which they are, but when someone types something into that cell I want it to take whatever the new contents of that cell are and update it back into my database. Right now, I'm using alert("input event fired"); just to test, but I'm doing something wrong.
  6. This was really helpful pointing me in the right direction - I've been reading for a few hours now on these different "print" types and they're really interesting. I just wanted to say thank you for your help I finally settled on the below: echo "<td>$" . number_format($row['Reg'],0) . "</td>"; to format my currencies. Your solution works fine for percentages.
  7. 2 for 2. thanks Reading up on blur, it seems like it takes focus away from something - I'm not sure how that enables me to do what I'm looking to do. I'm still in the learning phase of web development, so I'm not entirely sure how I would utilize this to accomplish what I'm looking to do. From the w3schools page on blur, there is a portion that (in theory) does exactly what I'm looking for: <input type="button" onclick="getfocus()" value="Get focus"> so when the button is clicked, it calls the function "getfocus()". If I could write something that could automatically call a function when I change the contents of the table cell, that would be perfect as I could put the code I want to execute inside that function. Is that possible?
  8. Yeah - I could always Yeah I guess I could change that - when I set the type I didn't think it was going to be for percentages. How would I go about using printf or number_format in the following string? while($row = mysqli_fetch_array($result)) { echo "<td>" . $row['RGP'] . "</td>"; }
  9. Coming from the world of Excel, I can easily format numbers as $1,500.00, or 27%. When I uploaded a large chunk of data into SQL to be read back through a table, the values all come out as exactly what they were uploaded as. For example, I have an SQL column set as Decimal(19,4) that I want formatted like currency, but which shows up as 1500.0000 in my table, or another column with type decimal(5,2) which shows up as 5500.0000, but which I want to show up as 55%. How do I do this?
  10. I have a table that has a cell that I've made editable: echo "<td contenteditable='true'>" . $row['Comments'] . "</td>"; Which is cool I guess, but it doesn't go anywhere from there. I'd like to make it so that upon changing, it links back to an SQL UPDATE query that I define. Is this possible through some sort of onChange function?
  11. edited - I had some comment lines in there where I shouldn't have This works perfectly now. Thank you SO much for your help!
  12. Awesome - that worked! All of the examples I'm finding (to try and learn) use mysql_query - which seems to not work anymore since it's been replaced with mysqli. It makes reproducing things very difficult. The only issue I'm having now is that I don't see where my drop-down selection is SAVED. The code is "working", in that the dropbox is now populated with the list I want. My only question now is - what variable is this saved to so i can pass it correctly into the SQL statement below: $result = mysqli_query($con,"SELECT * FROM report WHERE PMName = '$PMSelection'"); <html> <head> <script language="javascript1.2"> function submit( f ) { f.submit(); } </script> </head> <body> <form> <?php include('./db.php'); $PM = mysqli_query($con, "SELECT DISTINCT PMName FROM report ORDER BY PMName ASC" ); echo "<b>Select a PM:</b> \n"; echo " <select name='PMName' onChange='submit(this.form)'>\n"; while( $row = mysqli_fetch_row( $PM )) { $sel = ( $table === $row[0] ) ? "id='sel' selected" : ""; printf( " <option %s value='%s'>%s</option>\n", $sel, $row[0], $row[0] ); } echo " </select>\n"; echo " <input id='edit' type='button' value='GO' onClick='submit(this.form)'>\n"; ?> </form> </body> </html> <script language="javascript1.2"> //alert("I am an alert box!"); </script> <?php $PMSelection = $_POST["PM"]; $result = mysqli_query($con,"SELECT * FROM report WHERE PMName = '$PMSelection'"); echo "<table border='1'> <tr> <th>Track Number</th> <th>PM Name</th> <th>Reg NSB$ </th> <th>Total Backlog $ </th> <th>Average Backlog Margin by Track # </th> <th>Reg RGP% </th> <th>PM Comments </th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['TrackNumber'] . "</td>"; echo "<td>" . $row['PMName'] . "</td>"; echo "<td>" . $row['RegNSB'] . "</td>"; echo "<td>" . $row['TotalBacklog'] . "</td>"; echo "<td>" . $row['AverageBacklogTrackMargin'] . "</td>"; echo "<td>" . $row['RegRGP'] . "</td>"; echo "<td>" . $row['PMComments'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> This snippet: $PMSelection = $_POST["PMName"]; $result = mysqli_query($con,"SELECT * FROM report WHERE PMName = '$PMSelection'"); came from an earlier edition where I was manually typing in the name I wanted to see - as the whole POST reference isn't even in there anymore I'm not surprised this isn't working I just don't see where the dropdown list is passing on a variable, (maybe it's not...).
  13. I found another one that also seems very straightforward, but I can't get it to work for me either....: <?php include('./db.php'); //this is my connection info //SQL Query $query="SELECT DISTINCT PMName FROM report"; //Do Query $result = mysqli_query ($con,$query); echo "<select name='element_2' id='element_2'>"; while($row=mysql_fetch_array($result)) { echo "<option value='$row[PMName]'</option>"; } echo "</select>"; ?>
  14. It is not set anywhere. I don't even know what the specific function of $table does (as I just copied the example from another website to try and figure it out...)....
×
×
  • 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.