inspireddesign Posted June 3, 2009 Share Posted June 3, 2009 Hello all, I'm hoping someone can help with this one. Using the below code, I have a function that creates a table with their respective cells, stuff data accordingly and inserts the data into a RTF Word document. I'm able to create the table and cells just fine using the function below. My problem is that the first cells $sizeCell (width) is accepted but for whatever reason the second cell width is ignored. My thought is that it has to do with the size calculation but can't for the life of me figure out why. Thanks for any help on this one. The functions / I included everything that is called to create the cells: <?php function cell($msg, $sizeCell, $align="left", $cellColorId = NULL){ ### Calculate the size of the cell $sizeCell = (10800*($sizeCell/100)) + $previousResult; $previousResult = $sizeCell; ### Put the background color of the cell if ($cellColorId){$cell .= "\\clcfpatraw".$cellColorId."\\clshdngraw10000\n";} ### Assemble the cells of the table (the sum of the sizes of the cells should not exceed 21,600) $cell .= "\\cellx".$sizeCell."\n"; $cell .= "\\pard \\intbl "; $cell .= $msg." \\cell\n"; return $cell; } function open_line(){ ### Mount the table within the document $cell .= "\\trowd\\trgaph35\\trautofit1\\trpaddfr3\\trpaddfl3\\trpaddft3\\trpaddfb3\\trpaddr55\\trpaddl55\\trpaddb15\\trpaddt35\n"; return $cell; } function close_line(){ ### Go to the next line $cell .= "\\pard \\intbl \\row\\pard\n"; $previousResult=0; return $cell; } ?> And creating the cells: So in this example, I have the Message, The cell width, Color. The first cell("Aviation Products Manufactured / Serviced", "50", "left"); width is accepted but the second cell("Estimated Annual Sales", "50", "left"); width is ignored using the parameters (in this case 50). <?php if ($totalrow_prd > 0) { $listPrd = open_line(); $listPrd .= cell("Aviation Products Manufactured / Serviced", "50", "left"); $listPrd .= cell("Estimated Annual Sales", "50", "left"); $listPrd .= close_line(); do { ($corFundo == "8") ? ($corFundo = "16") : ($corFundo = "8"); $listPrd .= open_line(); $listPrd .= cell($row_prds['product_name'], "50", "left", $corFundo ); $listPrd .= cell($row_prds['product_sales'], "50", "left", $corFundo ); $listPrd .= close_line(); } while ($row_prds = mysql_fetch_assoc($prd)); } ?> Link to comment https://forums.phpfreaks.com/topic/160821-rtf-table-cell-sizing-issue/ Share on other sites More sharing options...
akitchin Posted June 3, 2009 Share Posted June 3, 2009 where should cell() be getting $previousResult from? you're not passing it to the function, and it's not globalized (which is a good thing). Link to comment https://forums.phpfreaks.com/topic/160821-rtf-table-cell-sizing-issue/#findComment-848779 Share on other sites More sharing options...
inspireddesign Posted June 3, 2009 Author Share Posted June 3, 2009 Thanks for the reply akitchin. Well... not sure. I thought I could declare it under close_line() (where it is now) but that doesn't seem to do the trick. I tried (recently) creating a public var and setting it to = 0 but that didn't help any. Any suggestions would be great? Thanks again! Link to comment https://forums.phpfreaks.com/topic/160821-rtf-table-cell-sizing-issue/#findComment-848794 Share on other sites More sharing options...
akitchin Posted June 3, 2009 Share Posted June 3, 2009 your best bet here is likely to add the $previousResult into the scope just above cell(), and pass it by reference to the function: function cell(&$previousResult, $msg, $sizeCell, $align="left", $cellColorId = NULL){ this will pass the $previousResult variable (see below for where we set it in the new code) by reference, which essentially tells the function to operate on that variable at the scope above the function. for more info, check the php manual for functions. $previousResult = 0; $listPrd = open_line(); $listPrd .= cell($previousResult, "Aviation Products Manufactured / Serviced", "50", "left"); $listPrd .= cell($previousResult, "Estimated Annual Sales", "50", "left"); $listPrd .= close_line(); this code will start the $previousResult variable at 0 before adding all your cells. if you toss it into your do {} block as well, it will reset it to 0 at the start of each row. this is obviously only a local solution for this issue. if you want a longer-term solution that resides within the functions themselves, you may need to rethink the functions and their arguments, but hopefully this gives you some ideas on how to do it. Link to comment https://forums.phpfreaks.com/topic/160821-rtf-table-cell-sizing-issue/#findComment-848842 Share on other sites More sharing options...
inspireddesign Posted June 3, 2009 Author Share Posted June 3, 2009 Man this is frustrating. Thanks for the help on this one. Unfortunately, your solution didn't work for me. I don't think it's seeing the $previousResult var even with forcing it into the function as you suggested (which I thought for sure would do the trick). I commented out + $previousResult $previousResult = $sizeCell; from within the function and that didn't even make a difference with the cell widths that are working. Meaning there was no change. So confused... ??? Link to comment https://forums.phpfreaks.com/topic/160821-rtf-table-cell-sizing-issue/#findComment-848861 Share on other sites More sharing options...
akitchin Posted June 8, 2009 Share Posted June 8, 2009 Man this is frustrating. Thanks for the help on this one. Unfortunately, your solution didn't work for me. I don't think it's seeing the $previousResult var even with forcing it into the function as you suggested (which I thought for sure would do the trick). I commented out + $previousResult $previousResult = $sizeCell; from within the function and that didn't even make a difference with the cell widths that are working. Meaning there was no change. So confused... ??? any chance we can see the revised script? note that there was an ampersand before $previousResult in the cell() definition. Link to comment https://forums.phpfreaks.com/topic/160821-rtf-table-cell-sizing-issue/#findComment-851794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.