Click here to Skip to main content
15,347,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have content stored in mysql, as following: 

<table width="210" cellspacing="1" cellpadding="1" border="0">
            <td><img width="513" height="680" align="left" alt="" src="/userfiles/image/pic.jpg" /></td>
            <td><img width="315" height="700" align="left" alt="" src="/userfiles/image/DSC_0389.JPG" /></td>
            <td><img width="580" height="320" align="left" alt="" src="/userfiles/image/ktxh.jpg" /></td>

When I load from db, PHP and display in html by PHP, there is no problem.

The $content it be read from mysql($child_article[6]) and display in html by dynamic code:

$sql_article = "select * from articles where approved=1 order by timestamp DESC"; @$childResult_article = general_query($sql_article); 
if ($child_article = mysql_fetch_row($childResult_article)) 
echo decode_data($child_article[6]). 

Now, I want all images, be displayed by fixed width and height as 200 X 200 AND TABLE BORDER = '0' ($content load from mysql by php and replace width and height of all images by 200 x 200 then echo $content to website)

What I have tried:

i tried, but can't result: 

$newWidth = 200; 
$newHeight = 200; 
$content = preg_replace( array('/width="\d+"/i', '/height="\d+"/i'), array(sprintf('width="%d"', $newWidth), sprintf('height="%d"', $newHeight)), $child_article[6]); 

How do I solve this problem?
Updated 18-Apr-19 10:31am
Member 14174664 17-Apr-19 5:20am
any body can help me!

1 solution

This strikes me as a very clunky design in any case. However, maybe it's outside of your control so you need a solution. Rather than trying to edit the guts of the HTML (the exact content of which may change at some point presumably), I'd be tempted to do it simply by setting the image dimensions in CSS. If you can be sure that the ONLY images within a table cell are the ones referred to, you can just include
td img {width:200px !important; height:200px !important;}
in your existing stylesheet. If not, the simplest thing is to add a classname to the <table> tag (just replace <table with <table class='img200' ) and add
table.img200 td img {width:200px !important; height:200px !important;}
to your stylesheet.
Member 14174664 2-May-19 4:14am
thanks DerekTP123

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900