Jump to content

TapeGun007

Members
  • Posts

    305
  • Joined

  • Last visited

Everything posted by TapeGun007

  1. Very good gentlemen and thank you. I think I've just read so much that after awhile it seemed like I was getting conflicting opinions. This helps to clarify greatly!
  2. I've read quite a bit about Date, DateTime, TimeStamp, and Time that after awhile, it's gets a bit confusing because everyone seems to have an opinion about which is best to do what in code examples. All I really want to do is store an appointment say, 05/23/22 at 10:00 AM and store that into the database, and be able to recall it later in that same format. Then I want to store when that appointment is going to end (which will always be the same day). So what would be the best route to take, so I can narrow it down. Like it is better to store the appointment date under the Date field and a separate value for the time the appointment started, or would it make more sense to store the appointment start time with a DateTime stamp instead? The part I'm not understanding from reading, is which one do you use for what scenario. I mean, I think Date is pretty simple. The Time field is weird, but I can see how you could use it to track the variance in time rather than a set calendar-like time like I'm doing. I believe I'm correct in saying that TimeStamp is really for tracking changes like... to a record and perhaps you have a timestamp for every time the record changes? I *think* I should use the DateTime for the start of the appointment and maybe just TimeStamp for the end of the appointment? Any advice or perhaps a link to better reading material would be greatly appreciated.
  3. That did the trick. Thank you kindly as always. Yeah, the while is correct as there can be multiple entries in a day.
  4. Oh I did exactly what was posted. I've just been super busy at work. I was contemplating just rewriting the entire page, but I just cannot find the time at the moment. Here is the entire piece of code: The rc_date is a Date field in the mySQL database. I used to have a well written calendar page, but... *sigh*... I cannot find it anywhere.
  5. @Barand, yes I know it's horrible code. I didn't write it. I was just trying to get it functional until I could get back to it and rewrite the entire page. @mac_gyver, yes it's in a loop. It's a calendar generated with HTML <table>'s. The echo was just to see what the db was outputting. As the calendar would come up to a specific date like today, it would bring up whatever was stored in the db called RepairCalendar for that date. There are deprecated HTML attributes being used in the code, so I have to correct all of that as well. Very fun. I'll probably just rewrite the page from the ground up.
  6. In mySQL, I have a date field rc_date and it's formatted Y-m-d. I'm not sure if I have done this right...and I've read a ton of examples but here is the code: $sqlDate = $numYear."/".$numMonth."/".$i; $temp = date_create($sqlDate); $sqlDate = date_format($temp, "Y-m-d"); echo $sqlDate; $sql = "SELECT * FROM RepairCalendar WHERE DATE(rc_date) = '".$sqlDate."'"; $stmt = $pdo->prepare($sql); $stmt->execute(); This is by no means optimized code. When I output echo $row['rc_date']; there is nothing. In the $sql statement, I tried just putting rc_date = $sqlDate. I tried using date_format in comparing the two dates as well which nothing seems to work. Whatever the case, I'm stumped as to what I'm doing wrong after reading so many examples. I had the echo statement just to ensure that the $sqlDate coming out correctly.
  7. Hrmmm.... I see. I was thinking the error was related to the issue where if I draw a line on the canvas, and then double click it, the red circles are supposed to draw at the beginning and ending of the line. The code to resize the line isn't yet implemented as I've been stuck on why the red circles do not draw when double clicking on the line. Apparently, it's unrelated and so back to the drawing board.
  8. I'm getting this error and I'm not sure what's causing it. I'm a little newer to JS. I'm using the fabric framework so to speak. It takes place on line 101 in the function updateNewLineCoordinates where it says: I am hoping someone can help me fix the error. Here is the code: let canvas = new fabric.Canvas("canvas", { width: window.innerWidth, height: window.innerHeight }); let addingLineBtn = document.getElementById('adding-line-btn'); // DrawBtn is the button pressed let addingLineBtnClicked = false; addingLineBtn.addEventListener('click', activateAddingLine); // call function activeAddingLine, then define it later function activateAddingLine() { if(addingLineBtnClicked===false) { // If you don't set this to false, then each time you click the Draw Line button, you have to also click the Select button or it will draw a new line when dragging another. addingLineBtnClicked = true; canvas.on('mouse:down', startAddingLine); // when mouse is down call function startAddingLine canvas.on('mouse:move', startDrawingLine); canvas.on('mouse:up', stopDrawingLine); canvas.selection = false; // this keeps the default selection box turned off. I want that option only when I choose to have it. canvas.hoverCursor = 'auto'; // When hovering over a line, it does not show that default MOVE cursor with 4 arrows. objectSelectability('added-line', false); } } let line; // Make a global variable so it can be called in other functions let mouseDown = false; // must be set to false so it can be "True" when actually pressed function startAddingLine(o) { mouseDown = true; let pointer = canvas.getPointer(o.e); line = new fabric.Line([pointer.x, pointer.y, pointer.x, pointer.y], { // we need 4 coordinates x,y where the line started, and x,y where it ended id: 'added-line', stroke: 'black', strokeWidth: 3, selectable: false // Set so you won't drag a drawn line on accident, but the move cursor pops up by default anyway. }); canvas.add(line); // will draw the line canvas.requestRenderAll(); // now rend the draw line being drawn } function startDrawingLine(o) { if(mouseDown===true) { let pointer = canvas.getPointer(o.e); line.set({ x2: pointer.x, // x2: Math.round(number / 10) * 10, // Not sure if this will round to closets 10 or not since line won't draw. y2: pointer.y }); canvas.requestRenderAll(); // Will actually render the line drawn } } function stopDrawingLine() { line.setCoords(); // This must be set for fabric to store the location of the line drawn so you can store or select it later. mouseDown = false; // set mouseDown to false so it will quit drawing the line } let deactivateAddingShapeBtn = document.getElementById('deactivate-adding-shape-btn'); deactivateAddingShapeBtn.addEventListener('click', deactivateAddingShape) function deactivateAddingShape(){ canvas.off('mouse:down', startAddingLine); // These functions now turn canvas.off so it will no longer keep drawing. canvas.off('mouse:move', startDrawingLine); canvas.off('mouse:up', stopDrawingLine); objectSelectability('added-line', true); canvas.hoverCursor = 'all-scroll'; // set cursor to the drag icon when hovering in area. addingLineBtnClicked = false; // Set to false or you will not be able to draw in the addingActivateLine function. } function objectSelectability(id,value) { canvas.getObjects().forEach(o => { // without this little bit of code, original lines drawn will be moveable without hitting the select button and when selecting and moving, it will draw another line. if(o.id===id) { // this is bascially a bug fix for drawing lines because of the way the buttons we programmed work. o.set({ // Youtube for this reasoning can be found here: https://www.youtube.com/watch?v=IQgeefO849w&list=PL-gIJFyHJjykXg776HNz3H7XXzBMSu5mL&index=4 selectable: value }) } }); } canvas.on({ // this is so that when you move the line, the dblclick circles on the ends move with it. 'object:moved': updateNewLineCoordinates, 'selection:created': updateNewLineCoordinates, 'selection:updated': updateNewLineCoordinates, 'mouse:dblclick': addingControlPoints }); let newLineCoords = {}; function updateNewLineCoordinates(o) { // this calculates from center of line and uses the offsets of x,y to move editing circles with the line. newLineCoords = {}; let obj = o.target; if(obj.id==='added-line') { let centerX = obj.getCenterPoint().x; // Gets the X coordinate of the center of the line drawn let centerY = obj.getCenterPoint().y; // Gets the Y coordinate of the center of the line drawn let x1offset = obj.calcLinePoints().x1; // Now calculate the end beginng and ending of each line to place the red circle for editing the line (so you can drag and make the line bigger or shorter) let y1offset = obj.calcLinePoints().y1; let x2offset = obj.calcLinePoints().x2; let y2offset = obj.calcLinePoints().y2; newLineCoords = { // places circle at the end of each line x1, y1 being the beginning of the line x1: centerX+x1offset, y1: centerY+y1offset, x2: centerX+x2offset, y2: centerY+y2offset } } } w function addingControlPoints(o) { let obj = o.target; if(!obj) { // If there is no object, then strokeWidth is not defined so it will throw an error in console. return; } else { if(obj.id==='added-line') { // All lines are given the 'added-line' id so we can select them later. let pointer1 = new fabric.Circle({ // These circles are so you can resize the line, there are no defaults for this, so we are creating it. radius: obj.strokeWidth*3, fill: 'red', opacity: 0.5, top: newLineCoords.y1, left: newLineCoords.x1, originX: 'center', // these two lines place the red editing circle dead center on the end of the line. originY: 'center' }); let pointer2 = new fabric.Circle({ // This is the other end of that line we want to resize. radius: obj.strokeWidth*3, fill: 'red', opacity: 0.5, top: obj.y2, left: obj.x2, originX: 'center', // these two lines place the red editing circle dead center on the end of the line. originY: 'center' }); canvas.add(pointer1,pointer2); canvas.requestRenderAll(); } } }
  9. So... I'm more of a PHP/mySQL guy. I'm going to be attempting to program a graph drawing type of program that I want to be specifically web based. Here is what I would like to accomplish (hopefully, it will make sense): I need a grid just like graph paper, only smaller, tighter squares. I want to draw lines that will snap to that grid. While the line is being drawn, it should say how many feet that line is. Once the line is drawn, I should be able to select it and move it or resize it. It needs to work with both mouse and touchscreen. I want to be able to save the graph and all the drawings on it and be able to recall them later. I have found a few examples that do various elements of the above, but I cannot seem to figure out how to combine them into a single program. If you have any places I can go to read about this, I'm more than willing to read and learn. Basically, I'll be graphing homes from a birds eye perspective. Here is my work so far: https://depests.com/leads/test/graph2.html - This has a graph and the object snaps to grid. https://depests.com/leads/test/test2.html - This allows me to draw lines, but they don't snap to a grid. https://depests.com/leads/test/test3.html - This tracks mouse and/or ipad touch movement, so I have something as sort of a guide on touch/mouse functionality.
  10. Barand, Thanks as always. I did discover through my trials and errors that the conditions in the WHERE clause were causing some issues. After much reading I had put them in the JOIN ON section, but you confirmed what I wasn't 100% sure of. So your definition confirms also that I was supposed to use the INNER JOIN because I did only want to show records if the match was in both tables. I did not know that LEFT JOINS were much slower however, that part I had not yet discovered.
  11. Is this a less correct way to write it then? This gave me the result I was looking for, but being a bit OCD, I like to ensure I'm writing solid code. SELECT * FROM Deals INNER JOIN Prospects ON Prospects.ProspectID = Deals.ProspectID AND Deals.Status = 'Won' AND Deals.PIGLead = ? ORDER BY SoldDate DESC Yeah, I just put the * in there to shorten it.
  12. Ok never mind. I got it. I had to use an INNER JOIN. I had also made an error above, the Status column was set to "Won" not "Sold". Thanks for helping me get on the right path.
  13. ON Prospects.ProspectID = Deals.ProspectID AND Deals.PIGLead = 2 WHERE Deals.Status = 'Sold' So... the ON line works sort of, but it lists clients that nothing was sold to. So I tried the WHERE above and now nothing comes up. LOL.
  14. Ok, so I was on the right track. I wrote this code: SELECT Prospects.ProspectID, Prospects.FirstName, Prospects.LastName, Prospects.Address, Prospects.Address2, Prospects.City, Prospects.State, Prospects.Zip, Deals.ProspectID, Deals.Product, Deals.Price FROM Prospects LEFT JOIN Deals ON Prospects.ProspectID = Deals.ProspectID So this works. But how can I narrow it down to just like WHERE PIGLead = 2 ? I now see why Union does not work, there would not be an equal amount of rows returned (if I'm understanding this correctly).
  15. I've been reading so many websites about LEFT JOIN, and now UNION, so before I go off on a major rabbit trail please help me figure out which is best by telling you what I want to accomplish. I'm going attach two images of my tables: The first table is called Prospects, and the 2nd table is simply called Deals. I'm going to try to write what I want in a non working version of code, but I hope it will translate what I want better: Under Table Deals, the field Status must be equal to "Sold" Under Tables Deals and Prospects, the ProspectID must match Under Table Deals, the PIGLead must be equal to 2 I want the table to show the Prospect information (name, address, phone, etc), then under the Prospect information, I want to see the deals sold to them where Status = "Sold". I want to see the Product and Price. Best method?
  16. Is it better or are you able to auto insert a percentage based upon a value. Example: Tech1 sells a $1,000 referral item and gets 5% commission Tech1 sells a $2,500 referral item and gets 7% commission instead. I know I could code this in php no problem. I'm just wondering if this makes sense or if it's possible just to auto insert either 5% for under $2,500 or 7% if the sale is equal or over $2,500. There is only 5% and 7%, no other options. The sale amount is stored in the same table.
  17. New question related to this. So... when a new prospect is created, the database inserts an automatic value of null. But then I set a follow up date and then when that date passes, I need to reset that value to a null. I simply put if $followupdate !isset then $followupdate = null; But when $followupdate is written to the database, it is now "0000-00-00" and I cannot seem to get the value back to null in mySQL. Everything works fine the way I have it, but call me OCD.
  18. Ah, I probably got some bad information in my reading, but I was under the perception that when the date is set to 0000-00-00 it is considered a NULL. This, of course, did not make sense to me. In my testing just now, I see the NULL value when auto inserted by mySQL. Thanks.
  19. Ah nvm, I got it unless there is a better way to write this, I would be interested. SELECT * FROM Prospects WHERE UserID = ? AND FollowUpDate < ? AND FollowUpDate > '0000-00-00'
  20. Not all items in my database have a due date. I already have a page that lists everything that is due today and that's fine. What I want to do is sort out all of the null dates "0000-00-00" but list the overdue items (past today) and not the current due dates (today's date). This was my failed attempt: $stmt = $pdo->prepare('SELECT * FROM Prospects WHERE UserID = ? AND FollowUpDate IS NOT NULL AND FollowUpDate < ?'); $stmt->execute([$ID,$today]); The above will list all the dates that are null anyway. I can't seem to figure out how to write this correctly. Thanks.
  21. Uh... thanks benanamen. Heheh. I kept searching, reading, and finally found the solution: $stmt = $pdo->prepare("SELECT SUM(Price) AS sumprice FROM Deals"); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo $row['sumprice'];
  22. This might be more of a mySQL question or a PHP question, I'm not exactly sure. I have a field in my table (Deals) called "Price". All I want is the sum of that field. I tried using something like: $price += $row['Price']; This ended up as one long string, even though the database is set as a decimal number field. Then I tried doing it from mySQL like this (from what I read), but I don't think I have the full answer: foreach($stmt->query('SELECT SUM(Price) FROM Deals') as $row) { echo "<tr>"; echo "<td>Total</td>"; echo "<td> ->".$row['SUM(Price)']."</td>"; echo "</tr>"; } Anyway, if someone could just show me how to get that sum, I would greatly appreciate it because I am missing something here.
  23. Just curious, but is it better to use a php framework say like Laravel than coding just plain php? And which framework do you recommend? I've read several websites that suggest Laravel is the better one but who knows who really posted that, so ... just curious from some real dev's what they prefer.
  24. I know you can query multiple DB's using UNION, but can you also UPDATE multiple db's, is that even possible? Not something I really want to do, but I'm trying to work around what I inherited until we hire internal dev's to fix this.
×
×
  • 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.