Jump to content

Export MySQL/Webpage to Word using PHP


blepblep

Recommended Posts

let's swap things round a little

 

    <?php
        mysql_connect("$host", "$username", "$password")or die("cannot connect");

        mysql_select_db("$db_name")or die("cannot select DB");
          
        $user_result = "SELECT review.*, mom.*, action.*, remark.* FROM review
        LEFT JOIN mom on review.reviewId = mom.reviewId
        LEFT JOIN remark on review.reviewId = remark.reviewId
        LEFT JOIN action on review.reviewID = action.reviewId
        WHERE review.reviewId IN ( ".$_POST['reviewIds']." )";

        $qry = mysql_query($user_result) OR die(mysql_error());

echo "<h1>TC Tool Minutes of Meeting</h1>";
while ($user_array = mysql_fetch_assoc($qry)) {

        echo "<table width='100%'>";
        // header row
        echo "<tr>                                                  
                <th>Review Forum</th>
                <th>Review ID</th>
                <th>Document Title</th>
                <th>Document Number</th>
                <th>Document Type</th>
                <th>Project Name</th>
                <th>Author Name</th>
                <th>Chairperson</th>
              <tr>";
        
                
            // data row
            echo //"tr> <- Puts a space under Review forum and its value.
                "                                                
                  <td>{$user_array['reviewForum']}</td>
                  <td>{$user_array['reviewId']}</td>
                  <td>{$user_array['docTitle']}</td>
                  <td>{$user_array['docNumber']}</td>
                  <td>{$user_array['docType']}</td>
                  <td>{$user_array['projectName']}</td>
                  <td>{$user_array['authorName']}</td>
                  <td>{$user_array['chairPerson']}</td>
                 ";
        
        echo "</table>"; 
        
        echo "<table width='100%'>";
        echo "<tr> 
                <th>Revision</th>
                <th>CDM Link</th>
                   <th>Main Requirement ID</th>
                <th>Mars Link</th>
                   <th>Checklist Link</th>
                   <th>Link Internal 1/3</th>
                <th>Impacted Products</th>
                <th>Scope</th>
                <th>Impacted Products 2</th>
                <th>Review Class</th>
                <th>Review Type</th>
                <th>Earliest Date</th>
                <th>Latest Date</th>
                <th>Previous TC Reviews</th>
                <th>Required Attendees</th>
                <th>Optional List</th>
                <th>Information Only</th>
                <th>Review Duration</th>
                <th>Document Abstract</th>
              </tr>";

            // 2nd data row
            echo "<tr>
            <td>{$user_array['revision']}</td>
            <td>{$user_array['cdmLink']}</td>
            <td>{$user_array['mainReqId']}</td>
            <td>{$user_array['marsLink']}</td>
            <td>{$user_array['checklistLink']}</td>
            <td>{$user_array['linkInternalOneThird']}</td>
            <td>{$user_array['impactedProducts']}</td>
            <td>{$user_array['abstract']}</td>
            <td>{$user_array['impactedProducts2']}</td>
            <td>{$user_array['reviewClass']}</td>
            <td>{$user_array['reviewType']}</td>
            <td>{$user_array['earliestDate']}</td>
            <td>{$user_array['latestDate']}</td>
            <td>{$user_array['previousTcReviews']}</td>
            <td>{$user_array['requiredAttendees']}</td>
            <td>{$user_array['optionalAttendees']}</td>
            <td>{$user_array['informationOnly']}</td>
            <td>{$user_array['reviewDuration']}</td>
            <td>{$user_array['docAbstract']}</td>
            </tr>";
        echo "</table>";
        }

        mysql_close();
    ?>

 

Sorry for the late reply Barand, I was finished work on Friday.

 

The above works perfectly, thank you! I have another question to ask you about, sorry :)

 

See the screenshot below, is there a way to widen the document itself so all of the information is visible? See how on the right here the column gets very narrow? The part where it is narrow is the last column -

 

21oribl.jpg

 

 

 

EDIT - Sorry, its a Monday morning :P I just put some of the results into another table so their on the next row.

Link to comment
Share on other sites

<rant>

 

Hey, blepblep,

 

This is obviously not your request, but your boss needs to be taught how business works.  He/she is wasting your time making you format a word document programmatically.    That's not how successful businesses are run.

 

You should be exporting to a CSV, and he/she should learn to use Excel to crunch numbers and/or format content into a document as applicable.  Better yet, he/she should learn SQL so he/she can generate his or her own reports!  Or buy a reporting package like Crystal to do it for him/her if he/she is lazy. 

 

Programmers should be developing products that can make the company money, not supporting lazy, inane execs who have no idea how technology works.

 

... not that I should be telling your boss how to run his biz... that's just how they work at the multi-billion-dollar company I work for (and every successful company I've ever worked for, for that matter).

 

</rant>

 

Cheers.

Link to comment
Share on other sites

I agree with smoseley, that's why I started this out by asking what are they trying to accomplish.  Apparently the answer is "they can't use commercial software packages so I have to write a program to do it for them."

 

If this is the way they approach technology, you'd better look for another job just in case.

Link to comment
Share on other sites

@smoseley - It's just how it is. I'm only a student doing work placement here so I can't really argue with what work I'm given you know? I understand where your coming from and it does seem pointless to me too but it has to be done  :-\

 

They want everything done for them, in their own words "It shouldn't take more than 3 or 4 clicks to have something done/get somewhere."

 

@ManiacCan, see above. I'm only here till 31st August though so its not too bad. Not at all what I thought it would be when I first came in given the massive size of the company and all its employees around the world.

Link to comment
Share on other sites

Not at all what I thought it would be when I first came in given the massive size of the company and all its employees around the world.
The bigger the company is, the dumber the employees are.  Big companies have people in them that do nothing other than summarize the work of the people below them.  If there's more than 3 people between you and the CEO, at least one of them does literally nothing of value.  Just because IBM produced Watson and Deep Blue doesn't mean that the guy running the summer intern program in Wisconsin has  PhD in artificial intelligence. 

 

If you want to work with mostly smart, capable people, you can either try to get into the R&D department at a large company, or work for a successful small company.  I always work for companies with fewer than 100 employees, and everyone I encounter is useful and intelligent (with some rare exceptions).  When I first started my career I worked at a large, older company.  I watched one guy in my department read a book for an entire week.  He got to work, checked his email, then put his glasses on and read Tom Clancy.  For 40 straight hours.  Small companies will notice that, big ones will not.

Link to comment
Share on other sites

Not at all what I thought it would be when I first came in given the massive size of the company and all its employees around the world.
The bigger the company is, the dumber the employees are.  Big companies have people in them that do nothing other than summarize the work of the people below them.  If there's more than 3 people between you and the CEO, at least one of them does literally nothing of value.  Just because IBM produced Watson and Deep Blue doesn't mean that the guy running the summer intern program in Wisconsin has  PhD in artificial intelligence. 

 

If you want to work with mostly smart, capable people, you can either try to get into the R&D department at a large company, or work for a successful small company.  I always work for companies with fewer than 100 employees, and everyone I encounter is useful and intelligent (with some rare exceptions).  When I first started my career I worked at a large, older company.  I watched one guy in my department read a book for an entire week.  He got to work, checked his email, then put his glasses on and read Tom Clancy.  For 40 straight hours.  Small companies will notice that, big ones will not.

 

This, exactly.  As an intern,  you'll find more to do at a start-up.  Have your hands in more interesting technology, etc. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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