Jump to content
Larry Ullman's Book Forums

Ordering Problem With Images - Database Retrieval


Recommended Posts

Hi,

 

I am experiencing a problem that I don't understand. I am retrieving records from a MySQL database. In each record there is a pointer to a jpg image file which is stored in a directory on the server.

 

I build a long string of html in a variable, including the retrieved jpg images. This html variable is then fed into PHPDOCX to generate a MS WORD document.

 

Randomly the images in the WORD document are not the correct image for that database record. Let me try and clarify: let's call a record retrieved from the database record 'a' which points to a jpg image file, say imga.jpg. The next record retrieved from the database, let's call it record 'b' which points to a jpg image file, say imgb.jpg.

 

Most of the time these will display correctly in the generated MS WORD document, but seemingly randomly, sometimes both record 'a' and record 'b' will show the imgb.jpg image.

 

I have inserted a clearstatcache(TRUE, $file_name)which seems to have reduced the number of these image errors but not all of them.

 

Does anyone have any ideas - if you do they will be most appreciated. Here's some of my code:

 

while (list(...lots of fields, $file_name)  = mysql_fetch_row($r1))
{..... html table header stuff...
// now a 'data' line	
$icon_file_name = substr($file_name, 0, -4); // chop off the .jpg
$icon_file_name = "../../dir1/dir2/" . $icon_file_name . "_icon.jpg";
$html .= "<tr valign='top'> 
...other table row data...						
<td align=\"left\"><img width='100%' src='$icon_file_name'></td>
</tr>";
clearstatcache(TRUE, $icon_file_name);
...etc...
My environment is:

. Windows 7 Home Premium 64 bit

. Internet Explorer 10

. Firefox 22.0

. Dreamweaver CS5 as the text editor

. Flex 4 via FlashBuilder 4

. PHPDOCX PRO 3.7

. XAMPP for Windows 1.8.3 which comprises:

.. Apache 2.4.4

.. PHP 5.5.3

.. MySQL 5.6.11

.. phpMyAdmin 4.0.4

 

Note: I can't use the mysqli functions as they are not supported by the production hosting site.

 

Any assistance/ideas will be most appreciated.

 

Thanks and Cheers.

Link to comment
Share on other sites

Hi Larry and Hartley-san,

 

Thanks for the suggestion. I did this, both as a dump to the screen and also writing the $html variable to a .doc file with fwrite. Echo-ing to the screen causes the program to go into some sort of loop, but writing the $html variable to the .doc file works just fine. And when I do this (as well as the PHPDOCX stuff), it works perfectly!!

 

So I'm guessing that it's something to do with the PHPDOCX functionality. I'm using the 'convert html to .docx' approach but I see from their documentation that there is another way to create a table in PHPDOCX - I might give that a try too.

 

Again, thanks for your thoughts and cheers from Oz.

Link to comment
Share on other sites

Hi Larry and Hartley-san, After carefully examining the documentation and code samples that came with PHPDOCX PRO, I discovered that there are two ways of creating a MS WORD document which contains a table - one is via converting html to WORD, which is the way that I used above and which gave me the errors also described above, and the other way is to create the WORD table 'natively' using PHPDOCX's table functionality.

 

FYI I finally figured out how to do it the 'native' way and it works a treat. I was led to my solution by very carefully examining some of the code samples supplied and basing my code on the code structures in the samples. I have to say that PHPDOCX is very feature-rich and even with my OK table, I have only scratched the surface of its capabilities.

 

Thanks again for your interest and suggestions.

 

Cheers from Oz.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...