Jump to content

TapeGun007

Members
  • Posts

    307
  • Joined

  • Last visited

Posts posted by TapeGun007

  1. Table "Deals":

    DealID (Yeah that's an L and then a capital i)

    Product

    Price

    Date

    Status (I only care about the deals that are marked as "won")

    ProspectID

    Table "Prospects":

    ProspectID

    FirstName

    LastName

    Address

     

    I could probably code this just fine, but I know it would be a horrible way to code it, so I'm asking for help on the proper way to code it.  I want to display a deal that was sold, and then reference the first, last name and address of that deal.

    For example:

    Termite Treatment |  $800 | 7-31-22 | Bob | Matthews | 123 Nowhere

    I suppose it should show the other way around too with the client info first and then each deal.

    I know that I could run the initial mySQL to pull the deal information and when it gets to the prospect id, run another query to pull the rest of the information, however, I am quite certain this would be the completely WRONG way to do it.  Then I discovered the JOIN commands, and I assume it would be an INNER JOIN?  The part where I get a little lost is that there are multiple deals under a Prospect.

    Any guidance would be appreciated.

  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. 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:

    Quote

    if(0 != $dayOfWeek) { echo('<td colspan="'.$dayOfWeek.'"> </td>'); }

    for($i=1;$i<=$daysInMonth;$i++) {

        if($i == $numDay) { echo('<td id="today" bgcolor="#cccccc" valign="top">'); } else { echo("<td valign='top'>"); }

        echo "<a href='calendarday.php?day=".$numMonth.$i.$numYear."'>".$i."</a>";

        echo "<br>";

        $sqlDate = $numYear."/".$numMonth."/".$i;

        $temp = date_create($sqlDate);

        $sqlDate = date_format($temp, "Y-m-d");

       

       

        $sql = "SELECT * FROM RepairCalendar WHERE DATE(rc_date) = ?";

        $stmt   = $pdo->prepare($sql);

        $stmt->execute( [ $sqlDate ] );

        while ($row = $stmt->fetch());

        {

            echo $row['rc_date'];  // Echos nothing

    }

        echo("</td>");

        if(date('w', mktime(0,0,0,$numMonth, $i, $numYear)) == 6) {

            echo("</tr><tr>");

        }

    }

    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.

  4. @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. 

     

  5. 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.

  6. 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.

  7. 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:

    Quote

    if(obj.id==='added-line') {

    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();
            }
        }
    }

     

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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).

  14. 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:

    1624731621_ScreenShot2019-04-21at7_54_33PM.png.a019f597aacc60e10da01ce12c3cf7a3.png1806086938_ScreenShot2019-04-21at7_55_04PM.png.28f685a3f488601f613a17d83b040fee.png

    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?

  15. I believe this would be a JS question, but I could be wrong:

     

    I query a database, it creates a table with all the matches, and then I click "Edit" next to one of the matches which passes an id so I can edit the user info.  However, if I click 'Back' in the browser, I get the usual

     

     

     

    Confirm Form Resubmission

    This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed.

     

    • Press the reload button to resubmit the data needed to load the page.
    ERR_CACHE_MISS

     

    Is there a way to create a back button that would basically resubmit that form or is that even possible?  Yes, I don't want to have to re-click "refresh" to populate the form again. Call me lazy, I don't care. :)

  16. Ah.  Dadgum it, I really worked hard trying to figure out the error on my own.  Now I understand.  I had thought about that, but what I also misunderstood is that the last CSS code always overwrites the first CSS code... which apparently is NOT true.

     

    But yes, that fixed it, and I'm very grateful for all your help!!!!  I feel like you really went the extra mile on this.. and it's very much appreciated.

  17. Hi Psycho,

     

    I already changed the color back to #99000 (I was just testing to see what that did).  This is not the issue.

     

    The *ONLY* difference between your picture and my picture is that under the "drivers" menu option (set to active), you have a background of #f6f6f6 (for "add driver" and "search drivers") and I have background color of #99000.  This is what I'm trying to understand.  I thought maybe it was a browser issue, but I tried this in Chrome, Firefox, and Edge all with the same result.

     

    Here is my entire code:

    <?php
    //definition of available menu
    $menuLinks = array(
        'Home' => array(
            'href' => 'Home.php'
        ),
        'Territory Manager' => array(
            'href' => 'tms.php',
            'children' => array (
                'Add TM' => '#',
                'Search TM' => 'search.php?search=TM'
            ),
        ),
        'Sales' => array(
            'href' => 'sales.php',
            'children' => array (
                'Add Sales Person' => '#',
                'Search Sales' => 'search.php?search=sales'
            ),
        ),
        'Drivers' => array(
            'href' => 'testcss.php',
            'children' => array (
                'Add Driver' => '#',
                'Search Drivers' => 'testcss.php'
            ),
        ),
        'Passengers' => array(
            'href' => 'passengers.php',
            'children' => array (
                'Add Passenger' => '#',
                'Search Passengers' => 'search.php?search=passengers'
            )
        )
    );
    //Function to create html content for menu
    function createMenu($menuLinks, $webpage=false)
    {
        $menuLinksHtml = '';
        foreach($menuLinks as $parentLabel => $parentLink)
        {
            //Determine link if parent is active or not
            $active = ($webpage == $parentLink['href']) ? ' active' : '';
            $menuLinksHtml .= "<li class=\"dropdown{$active}\">\n";
            //Determine if parent link has children
            if(!isset($parentLink['children']))
            {
                //No child elements
                $menuLinksHtml .= "<a href='{$parentLink['href']}'>{$parentLabel}</a>\n";
            }
            else
            {
                //Has child elements
                $menuLinksHtml .= "<a href=\"javascript:void(0)\" class=\"dropbtn\">{$parentLabel}</a>";
                $menuLinksHtml .= "<div class=\"dropdown-content\">\n";
                foreach($parentLink['children'] as $childLabel => $childLink)
                {
                    $menuLinksHtml .= "<a href=\"{$childLink}\">{$childLabel}</a>\n";
                }
                $menuLinksHtml .= "</div>\n";
                
            }
            $menuLinksHtml .= "</li>\n";
        }
        //Return HTML content
        return $menuLinksHtml;
    }
    ?>
    
    <!DOCTYPE HTML>
    <html>
    <head>
        <!-- <link rel="stylesheet" type="text/css" href="components/css/rs.css"> -->
        <style>
            
            /***** Begin Menu CSS *****/
    ul {
        width: 100%;
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #333;
    }
    li {
        float: left;
    }
    li a, .dropbtn{
        display: inline-block;
        font-size: 15px;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
        border-right: 1px solid #bbb;
    }
    /* Color of the main menu text when hovering */
    li a:hover { 
        background-color: red;
    }
    /* Once the mouse has moved off the main menu button and is now highlighting a sub menu button, this defines what that main menu button color is */
    .dropdown:hover{
        background-color: red;
    }
    /* Color of main menu button when not selected */
    .dropbtn {
        background-color: 333;
    }
    li .dropdown {
        position:relative;
        display: inline-block;
        
    }
    li:last-child {
        border-right: none;
    }
    .dropdown-content{
        display: none;
        position: absolute;
        background-color: #f9f9f9;
        min-width: 160px;
        box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2);
        z-index: 1;
    }
    /* Links inside the dropdown */
    .dropdown-content a{
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
        text-align: left;
        background-color: #f6f6f6; /* Sets background color of the drop down menu (not selected) */
    }
    /* Change color of dropdown links on hover */
    .dropdown-content a:hover {background-color: #ccc}
     
    .dropdown:hover .dropdown-content{
        display: block;
    }
    /* I have no idea what this does as it appears nothing...
    li a:hover:not(.active) {
        background-color: #blue;
    } */
    li.active a {
        background-color: #990000;  
    }
    .active dropdown-content{
        display: none;
        position: absolute;
        min-width: 160px;
        box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2);
        z-index: 1;
    }
    .active dropdown-content a{
        color: black;
        padding: 12px 16px;
        text-decoration: none;
        display: block;
        text-align: left;
    }
    li.active a.dropbtn {
        background-color: #990000;  
    }
    /***** End Menu CSS *****/
        </style>
    </head>
    
    <body>
    <ul>
        <?php echo createMenu($menuLinks, "testcss.php"); ?>
    </ul>
    </body>
    </html>
    
    
    
  18. That's very odd.  Your picture is exactly how I would like it to look, but on my screen... it's like the picture above (minus the dark red Home button).  Can you re-post your entire page code?

     

    I did go into Chrome and completely delete all cached files and such just to be sure.

  19. li.active a.dropbtn {
        background-color: #f6f6f6;  /* This set the background of the actively selected top menu item */
    }
    

    What that does is makes the word "Driver" on the main menu turn to a light gray.  But it doesn't change the background color of the drop down box.

  20. Yeah, I had noticed and was trying to find the issue.  But drop down box of the selected item is still dark red (background) even with that.  The background of a the active item drop down should be #f6f6f6 (or whatever other color).

×
×
  • 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.