Posts

Showing posts with the label join

Using phpword to merge two Mircrosoft Office Word .docx documents

How to combine or embed and insert another .docx file (Microsoft office docx word document) into another one using PHPWord Joining two .docx document using php ( phpword library ) $mainTemplateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("file1"); //$mainTemplateProcessor ->setValue('var_name', $value); $innerTemplateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("file2"); //$innerTemplateProcessor->setValue('var2_name', $value2); // extract internal xml from template that will be merged inside main template $innerXml = $innerTemplateProcessor->gettempDocumentMainPart(); $innerXml = preg_replace('/^[\s\S]*<w:body>(.*)<\/w:body>.*/', '$1', $innerXml); // remove tag containing header, footer, images $innerXml = preg_replace('/<w:sectPr>.*<\/w:sectPr>/', '', $innerXml); // inject internal xml inside main template $mainXml = $mainTemplateProcessor->gettempDocumentMainPart(...

שליפת רשומה עדכנית ב - MySQL מתוך GROUP

במקרים רבים יש לנו טבלא בבסיס הנתונים המכילה אוסף רשומות של שינויי סטטוס הכוללים הסטוריה. משהו בדומה ל - בתאריך 2013-02-07, הועבר שחקן x לשרת s1 בתאריך 2013-02-07, הועבר שחקן y לשרת s2 בתאריך 2013-02-08, הועבר שחקן x לשרת s2 בתאריך 2013-02-09, הועבר שחקן x לשרת s3 בתאריך 2013-02-09, הועבר שחקן y לשרת s1 הטבלא תראה בערך כך: id date player server 1 2013-02-07 x s1 2 2013-02-07 y s2 3 2013-02-08 x s2 4 2013-02-09 x s3 5 2013-02-09 y s1 ואנחנו רוצים לשלוף את הרשומה העדכנית ביותר עבור כל אחד מהשחקנים. כלומר כל שחקן באיזה שרת הוא נמצא. שיטה מעניינת לעשות זאת, היא באמצעות left join query לאותה טבלא עצמה בצורה זו: SELECT     * FROM     table AS t         LEFT JOIN table AS t2 ON t.player=t2.player AND t.date < t2.date WHERE t2.date IS NULL זה ייתן לנו תוצאה כזו: id date player server 4 2013-02-09 x s3 5 2013-02-09 y s1 לקריאה נוספת: stack over...