Jump to content

Adamhumbug

Members
  • Posts

    590
  • Joined

  • Last visited

Posts posted by Adamhumbug

  1. 7 minutes ago, ginerjm said:

    So you are reading a pdf document.  You said that this has "some divs".  Are those really divs, as in html/css div tags?  Or are you trying to say that you have divided the page up into sections when you prepare it for print?

    Basically i am creating a page with no content apart from what i want to be in the pdf - so it opens in a new tab and is a cover page with dynamic title - that page is easy as the content will never overflow.

    For every page i have a div (called .a4) which i use to make sure the page is the right size to be printed into pdf.

    For page 2 onwards i also have divs with the a4 class to constrain the size.

    On page 2 it is very possible that the content will overflow and be longer than the a4 size - i really cant see a good way to break this onto a new page as i have positioned header and footer images.  I would need to have one div that spanned more than one page and head margin from the top and bottom of every page that it is on.  Pretty sure i cannot do that.

    I may have to look for another solution ... but im so close to this working.

    Trying to avoid the wasted time.

  2. Just now, Adamhumbug said:

    Agreed, that is why i am creating a page that prints into PDF, can be mailed around and that document printed.

    I did have a go with FPDF a couple of years ago and didnt get very far so i thought i would look for another option.  What i have so far looks good when Printed to PDF asside from the fact that it wraps half way through a line of text.

  3. 1 hour ago, ginerjm said:

    What is displaying the page?  HTML? ? FPDF?

    If HTML then your css would handle the page breaks for you.  Read up on that.

    If it is FPDF (or some other pdf generator) you would have to do with your php(?) code that is outputting the display

    it is html yes - i didnt commit to learning fpdf as i need a header and footer and there is a lot of style involved.

  4. Hi All,

    I am creating a quote builder that has a display page showing all of the items that are in the quote.

    This has some divs that are a4 size representing the pages (this will be printed into pdf)

    When the content is longer than the container, how would i break this onto a new page (it would then be in a new div).

    I am not sure what language this would be so apologies if this is more likely JS than PHP.

  5. Hi All,

    I am looking for some suggestions here on a good way to order items.

    I have a table that has an id, name and display order columns.

    I am looking for suggestions on the best way (in a ui) to set the display order of each item without having the same value as any other item.

    So the items table looks like this.

    Item Name    -     Display Order

    Item 1.            -     1

    Item 2.           -     2

    Item 3.           -     3

    I want to be able to change the display order and automatically rearrange everything else.

    I can think of many crude ways to change the order but none that would update the rest.

    I want to be able to add Item 4 and it have display order 2 - item2 and item3 would have their display orders increased to move down.

    As always, appreciate your input.

  6. I am always looking to get better and i get most of my tips from here - i will bare that in mind.  I do have another question on the answer that has been given for this question.

    I have the following to generate my HTML - based on the info provided in the answer.

    if in the second for each loop i want to access one of the $items which i dont iterate through until the third for each - how would i go about doing that.

     foreach ($results as $client => $jobs){
            
            foreach($jobs as $j => $items){
                
                    foreach($items as $item){    
                    }       
            }
      }

    Basically, one of the $items has a status and i want to change the colour of the table row that is created depending on this - but the table rows are created in the second for each.

  7. 36 minutes ago, Barand said:

    You don't want to help - too much to ask?

    OK - Here's how it looks with my data...

    +-----------+-----------+------------+-----------+-------------------+------------+
    | member_id | user_name | first_name | last_name | email             | phone      |
    +-----------+-----------+------------+-----------+-------------------+------------+
    | 1         | cheggs    | Scott      | Chegg     | cheggs@ggmail.com | 1345678902 |
    | 2         | norderl   | Laura      | Norder    | lauran@ggmail.com | 2345678901 |
    | 3         | canarit   | Tom        | DiCanari  | tomdc@ggmail.com  | 6543219878 |
    | 4         | peted     | Peter      | Dowt      | pete.d@ggmail.com | 9876543210 |
    | 5         | tonins    | Sarah      | Tonin     | saraht@ggmail.com | 7896321455 |
    +-----------+-----------+------------+-----------+-------------------+------------+

    code

    $res = $pdo->query("SELECT user_name
                             , last_name
                             , first_name
                             , email
                             , phone
                        FROM member
                ");
    $data = $res->fetchAll(PDO::FETCH_GROUP);            
    $result = [];
    foreach ($data as $u)  {
        $result[$u['user_name']][$u['last_name']] = array_slice($u,2);
    }
    echo '<pre>' . print_r($result, 1) . '</pre>';           

    results

    Array
    (
        [cheggs] => Array
            (
                [Chegg] => Array
                    (
                        [first_name] => Scott
                        [email] => cheggs@ggmail.com
                        [phone] => 1345678902
                    )
    
            )
    
        [norderl] => Array
            (
                [Norder] => Array
                    (
                        [first_name] => Laura
                        [email] => lauran@ggmail.com
                        [phone] => 2345678901
                    )
    
            )
    
        [canarit] => Array
            (
                [DiCanari] => Array
                    (
                        [first_name] => Tom
                        [email] => tomdc@ggmail.com
                        [phone] => 6543219878
                    )
    
            )
    
        [peted] => Array
            (
                [Dowt] => Array
                    (
                        [first_name] => Peter
                        [email] => pete.d@ggmail.com
                        [phone] => 9876543210
                    )
    
            )
    
        [tonins] => Array
            (
                [Tonin] => Array
                    (
                        [first_name] => Sarah
                        [email] => saraht@ggmail.com
                        [phone] => 7896321455
                    )
    
            )
    
    )

     

    Just seen this - sorry it took a while to reply.

    I have tried:

    $res = $pdo->query("SELECT client.company_name
                             , job.name as jobName
                             , version
                             , currency
                             , job.internal_ref
                             , kit_delivery
                             , kit_return
                             , quote_status_id 
                       from quote
                       inner join client on quote.client_id = client.id
                       inner join job on quote.job_id = job.id
                ");
        $data = $res->fetchAll(PDO::FETCH_GROUP);
        $result = [];
        foreach($data as $u){
            $result[$u['jobName']][$u['internal_ref']] = array_slice($u, 2);
        }
    
        echo '<pre>' . print_r($result, 1) . '</pre>';

    but i am getting "invalid array key" on jobName and internal_ref

  8. 1 hour ago, Barand said:

    Thanks, but pictures are real bastard to process.

    a var_export($array) with a few records would be much more useful.

    This is what i get for var export array - i hope i have used it correctly.

     

    array (
      'Test_Co' => 
      array (
        'Big Event Co' => 
        array (
          0 => 
          array (
            'jobName' => 'TEST TC',
            'version' => 0,
            'currency' => '1',
            'internal_ref' => '00000',
            'kit_delivery' => '2023-08-01',
            'kit_return' => '2023-08-03',
            'quote_status_id' => 1,
          ),
        ),
        'Test Co' => 
        array (
          0 => 
          array (
            'jobName' => 'Test',
            'version' => 0,
            'currency' => '1',
            'internal_ref' => '123',
            'kit_delivery' => '2023-08-01',
            'kit_return' => '2023-08-02',
            'quote_status_id' => 1,
          ),
          1 => 
          array (
            'jobName' => 'Second Job',
            'version' => 0,
            'currency' => '2',
            'internal_ref' => 'ref',
            'kit_delivery' => '2023-08-16',
            'kit_return' => '2023-08-25',
            'quote_status_id' => 1,
          ),
        ),
      ),
    )

     

  9. 2 minutes ago, Barand said:

    try

    $res = $pdo->query("SELECT client.company_name
                             , job.name as jobName
                             , version
                             , currency
                             , job.internal_ref
                             , kit_delivery
                             , kit_return
                             , quote_status_id 
                       from quote
                       inner join client on quote.client_id = client.id
                       inner join job on quote.job_id = job.id
                ");
    $data = $res->fetchAll(PDO::FETCH_GROUP);            
    $result = [ 'Test_Co' => $data ];
    
    echo '<pre>' . print_r($result, 1) . '</pre>';

     

    That gives the following

    Screenshot2023-08-24at21_31_35.png.a83b9466fabf1f21cacb79c7ec7cb85f.png

  10. Hi All,

    Arrays kill me - struggle to understand how to build them.

    Could anyone please help explain or point me to some good clear reading on how to build a multidemntional array with a select statement.

    here is the statement for reference

    SELECT client.company_name, job.name as jobName, version, currency, job.internal_ref, kit_delivery, kit_return, quote_status_id 
            from quote
            inner join client on quote.client_id = client.id
            inner join job on quote.job_id = job.id

    and here is the output

    Screenshot2023-08-24at21_17_22.png.43173c1368c6f05b9c27f1fcec2b201f.png

     

    I appreciate this is one record so not great for the explanation but i am trying to make an array 2 levels deep.

    1st level would be the client name "test co" and the second level would be the jobName "test" everything else would be the next level.

    I know this is not difficult but i just cannot get my head around it.

     

    I am getting data out of the current arrays fine with the following

    foreach ($quotes as $quote => $items) {
            $out .= $quote;
            foreach ($items as $item) {
                $out .= $item['jobName'];
            }
        }

     

  11. 4 minutes ago, Barand said:

    One more point, do not connect to your db server every time you call a function. Connecting is the slowest part of the process. Connect once at the start of the script and pass $pdo as an argument in the function calls (as with the other arguments that @ginerjm suggested).

    So dont "include/includes..." in each function, but when calling the function use "callingFunction($pdo, $otherThing)"?

     

    Ok sounds good.

  12. 2 hours ago, ginerjm said:

    Something that nobody has mentioned.  If you want to do this work inside of a function you probably want to make it usable in multiple situations.  Why then do you make it not portable by referencing an outside value that is not part of the function's header?  That is just not good programming.  Get rid of the $_GET reference and pass this 2nd value in using the parms in the function header.

    function removeItemFromQuote($itemId, $other_id)

     

    I have rewritten the function and done exactly this.  Closer looking and there were several problems with it. 

     

    All of your pointers have got me to the bottom of it - thanks all.

  13. HI All,

    I have a php function.

    function removeItemFromQuote($itemId)
    {
        include 'includes/dbconn.php';
        $sql = "DELETE from quote_items where id = :itemId";
        $stmt = $pdo->prepare($sql);
        $stmt->execute([
            ":itemId" => $itemId
        ]);
    
        $sql2 = "SELECT id, amount_charged_each, quantity, chargable_units from quote_items where quote_id = :qId";
        $stmt2 = $pdo -> prepare($sql2);
        $stmt2 -> execute([
            ':id' => $_GET['quoteId']
        ]);
    
        $total = 0;
        while($row = $stmt2 -> fetch()){
            $total += floatval($row['amount_charged_each']) * floatval($row['quantity']) * floatval($row['chargable_units']);
        }
    
        $sql3 = "UPDATE quote SET total_value = :total_value where id = :id";
        $stmt3 = $pdo -> prepare($sql3);
        $stmt3 -> execute([
            ':total_value' => $total,
            ':id' => $_GET['quoteId']
        ]);
    
    
    }

    The first part is running, the item is being deleted.

    The second and third dont seem to be working, certainly the total_value column is not being updated.

    I am not seeing any errors and i have this at the top of the page calling the function and in my functions file.

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    Is there something obvious that i am doing wrong?

  14. I have a php function that creates a chunk of html including a onclick call.

    The onclick function curerntly just console.logs what has been passed in.

    I am getting a "uncaught SyntaxError: missing ) after argument list" error and i cant for the life of me figure out why.

    $out .="<tr class='align-middle custom-lc' onclick='triggerClientContextMenu($cId, $coName)'>
                    <td>
                        <div class='companyName'>$coName</div>
                      ......
                      
                       </td>
                
                </tr>";

    When i inspect what is being put on the page i see

    <tr class="align-middle custom-lc" onclick="triggerClientContextMenu(1, Company Name)">
                    <td>
                        <div class="companyName">Company Name</div>

    all looks good to me asside from the error in the console.

    Annoyingly, the error in the console doesnt take me to a useful line of code just to the <!DOCTYPE html>.

    when i remove this onclick from the PHP, i dont get any errors and everything runs fine.

     

    Any pointers?
                     

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