zhangy Posted July 21, 2009 Share Posted July 21, 2009 Hi, I have an interactive blog where users can post information via mysql database. I ran into a problem today though when someone used what im assuming was html to post some images. Now I am all for the use of images as well as html in the posts like this however the space where data is displayed is only about 600 pixels in width, but the image they posted was almost twice that size so the image spilled into my navigation column and basically screwed up the look of the page. My question is: Is there a way to control the size of posts like this so that they will be resized to fit the column that they are displayed in? my current display code: <?php require_once('load_data.php'); if (!mysql_connect($db_host, $db_user, $db_pwd)) die('<strong style="color:maroon">Sorry, database undergoing maintenance. Please try again later.</strong>'); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT * FROM $table WHERE date BETWEEN UNIX_TIMESTAMP(DATE_SUB( CURDATE( ) ,INTERVAL 5 DAY )) and UNIX_TIMESTAMP( ) ORDER BY id DESC")or die(mysql_error()); while($row = mysql_fetch_array($result)) { $subject = $row['col_2']; echo '<div class="job_posts">'; echo '<h2>'; echo '<a href="position.php?id='.$row['id'].'" class="job_link">'.stripslashes(htmlspecialchars($row['col_4'])).'</a>'; echo '</h2>'; echo '--<em>'; echo '<a href="user.php?id='.urlencode($subject).'" title="recent posts by '.$row['col_2'].'">'.stripslashes(htmlspecialchars($row['col_2'])).'</a>'; echo '</em> '; echo date("M dS, Y", $row['date']); echo '<p>'; echo stripslashes(substr($row[col_5],0,350)).' <strong><a href="position.php?id='.$row['id'].'">Read more >></a></strong>'; echo '</p>'; echo "</div>"; } mysql_free_result($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/ Share on other sites More sharing options...
MadTechie Posted July 21, 2009 Share Posted July 21, 2009 Why not use css overflow: hidden Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/#findComment-879183 Share on other sites More sharing options...
zhangy Posted July 21, 2009 Author Share Posted July 21, 2009 Thanks MadTechie, That does work as a great partial or temporary solution but I would prefer something that could retain and display the data in its entirety if possible. Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/#findComment-879192 Share on other sites More sharing options...
MadTechie Posted July 21, 2009 Share Posted July 21, 2009 When you say resize the post, do you mean resize the image that entered via HTML ? Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/#findComment-879197 Share on other sites More sharing options...
zhangy Posted July 21, 2009 Author Share Posted July 21, 2009 yes, exactly. Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/#findComment-879232 Share on other sites More sharing options...
MadTechie Posted July 21, 2009 Share Posted July 21, 2009 Humm.. i don't like this solution but with your system being so open i guess it may work //replace images with a prefixed height or width $html = preg_replace('/<img.*?src=(["\']?)(.*?)\1.*?>/', '<img src="\2" height="100px">', $html); the correct solution is to not allow HTML but use BBcode instead Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/#findComment-879753 Share on other sites More sharing options...
Lambneck Posted July 22, 2009 Share Posted July 22, 2009 cool thanks! ill look into the bbcode too. i appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/166731-solved-define-dimentions-of-html-data/#findComment-880350 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.