帮助格式化 PHP 中的新闻条目
在我的网站上,用户可以登录并添加新闻。效果很好。我在尝试显示新闻时遇到问题。第一个问题是,如果新闻文本没有填充新闻图像旁边的所有空间,那么下一个新闻项目就会显示得太快(不在橙色断路器下方),正如您目前在网站上看到的那样。我想解决这个问题,我可以将每个新闻帖子 div 的高度设置为图像的高度,尽管图像比 div 短一点,所以我不确定如何做到这一点。
其次,用户在他们的新闻帖子中放置链接。如何让它们显示为活动状态?在 Firefox 上它们只是以文本形式出现。有人可以指出我正确的方向吗?
这是代码:
$query="SELECT id, date, title, text, author, media1, media2, deleted FROM news ORDER BY id DESC LIMIT 4";
$result=mysql_query($query);
$counter = 0;
$number1 = 1;
$number2 = 2;
while($row = mysql_fetch_array($result)){
if($row['deleted'] == 0) {
if (($counter % 2) == 0) {
echo '<div id="text">';
echo '<a name="'.stripslashes($row['title']).'" id="'.stripslashes($row['title']).'"></a>';
echo '<span class="kisstitle">'.stripslashes($row['title']).'</span><br>';
echo ' (';
echo $row['date'];
echo ')';
echo '<br>';
echo '<br>';
if((preg_match ("/\bjpg\b/",$row['media1'])) || (preg_match ("/\bjpeg\b/",$row['media1'])) || (preg_match ("/\bpng\b/i",$row['media1'])) || (preg_match ("/\bgif\b/i",$row['media1']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media1'].'" class="floatRightClear" id="border">';
}
if((preg_match ("/\bjpg\b/",$row['media2'])) || (preg_match ("/\bjpeg\b/",$row['media2'])) || (preg_match ("/\bpng\b/i",$row['media2'])) || (preg_match ("/\bgif\b/i",$row['media2']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media2'].'" class="floatRightClear" id="border">';
}
if((preg_match ("/\bmp3\b/", $row['media1']))) {
echo ' <p id="audioplayer_'.$number1.'" class="floatRightClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number1.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media1'].'"});
</script>';
echo '<br>';
}
if((preg_match ("/\bmp3\b/", $row['media2']))) {
echo ' <p id="audioplayer_'.$number2.'" class="floatRightClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number2.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media2'].'"});
</script>';
echo '<br>';
}
echo stripslashes(nl2br($row['text']));
echo '<br><br>';
echo stripslashes($row['author']);
echo '</div>';
echo '<p align="right" id="seperater"><a href="index2.php?op=News#top">Top</a><img src="images/seperater.jpg" width="950" height="6" style="border:none;" /></p>';
}
else {
echo '<div id="text">';
echo '<a name="'.stripslashes($row['title']).'" id="'.stripslashes($row['title']).'"></a>';
echo '<span class="kisstitle">'.stripslashes($row['title']).'</span><br>';
echo ' (';
echo $row['date'];
echo ')';
echo '<br>';
echo '<br>';
if((preg_match ("/\bjpg\b/",$row['media1'])) || (preg_match ("/\bjpeg\b/",$row['media1'])) || (preg_match ("/\bpng\b/i",$row['media1'])) || (preg_match ("/\bgif\b/i",$row['media1']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media1'].'" class="floatLeftClear" id="border">';
}
if((preg_match ("/\bjpg\b/",$row['media2'])) || (preg_match ("/\bjpeg\b/",$row['media2'])) || (preg_match ("/\bpng\b/i",$row['media2'])) || (preg_match ("/\bgif\b/i",$row['media2']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media2'].'" class="floatLeftClear" id="border">';
}
if((preg_match ("/\bmp3\b/", $row['media1']))) {
echo ' <p id="audioplayer_'.$number1.'" class="floatLeftClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number1.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media1'].'"});
</script>';
echo '<br>';
}
if((preg_match ("/\bmp3\b/", $row['media2']))) {
echo ' <p id="audioplayer_'.$number2.'" class="floatLeftClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number2.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media2'].'"});
</script>';
echo '<br>';
}
echo stripslashes(nl2br($row['text']));
echo '<br><br>';
echo stripslashes($row['author']);
echo '</div>';
echo '<p align="right" id="seperater"><a href="index2.php?op=News#top">Top</a><img src="images/seperater.jpg" width="950" height="6" style="border:none;" /></p>';
}
$number1++;
$number1++;
$number1++;
$number2++;
$number2++;
$number2++;
$counter++;
}}
On My Site users can login and add news. That works fine. I have problems when trying to display the news. First problem is if the news text doesn't fill all the space by the side of the news image, then the next news item gets displayed too soon (not below the orange breaker) as you can see on the site at the moment. I was thinking to get around this I could set the height of each news post div to the height of the image, although the image is a little shorter than the div so I'm not sure how I'd do that.
Secondly, users put links in their news posts. How do I get them to be displayed as active? on firefox they just come out as text. Could someone point me in the right direction please!
Here's the code:
$query="SELECT id, date, title, text, author, media1, media2, deleted FROM news ORDER BY id DESC LIMIT 4";
$result=mysql_query($query);
$counter = 0;
$number1 = 1;
$number2 = 2;
while($row = mysql_fetch_array($result)){
if($row['deleted'] == 0) {
if (($counter % 2) == 0) {
echo '<div id="text">';
echo '<a name="'.stripslashes($row['title']).'" id="'.stripslashes($row['title']).'"></a>';
echo '<span class="kisstitle">'.stripslashes($row['title']).'</span><br>';
echo ' (';
echo $row['date'];
echo ')';
echo '<br>';
echo '<br>';
if((preg_match ("/\bjpg\b/",$row['media1'])) || (preg_match ("/\bjpeg\b/",$row['media1'])) || (preg_match ("/\bpng\b/i",$row['media1'])) || (preg_match ("/\bgif\b/i",$row['media1']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media1'].'" class="floatRightClear" id="border">';
}
if((preg_match ("/\bjpg\b/",$row['media2'])) || (preg_match ("/\bjpeg\b/",$row['media2'])) || (preg_match ("/\bpng\b/i",$row['media2'])) || (preg_match ("/\bgif\b/i",$row['media2']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media2'].'" class="floatRightClear" id="border">';
}
if((preg_match ("/\bmp3\b/", $row['media1']))) {
echo ' <p id="audioplayer_'.$number1.'" class="floatRightClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number1.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media1'].'"});
</script>';
echo '<br>';
}
if((preg_match ("/\bmp3\b/", $row['media2']))) {
echo ' <p id="audioplayer_'.$number2.'" class="floatRightClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number2.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media2'].'"});
</script>';
echo '<br>';
}
echo stripslashes(nl2br($row['text']));
echo '<br><br>';
echo stripslashes($row['author']);
echo '</div>';
echo '<p align="right" id="seperater"><a href="index2.php?op=News#top">Top</a><img src="images/seperater.jpg" width="950" height="6" style="border:none;" /></p>';
}
else {
echo '<div id="text">';
echo '<a name="'.stripslashes($row['title']).'" id="'.stripslashes($row['title']).'"></a>';
echo '<span class="kisstitle">'.stripslashes($row['title']).'</span><br>';
echo ' (';
echo $row['date'];
echo ')';
echo '<br>';
echo '<br>';
if((preg_match ("/\bjpg\b/",$row['media1'])) || (preg_match ("/\bjpeg\b/",$row['media1'])) || (preg_match ("/\bpng\b/i",$row['media1'])) || (preg_match ("/\bgif\b/i",$row['media1']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media1'].'" class="floatLeftClear" id="border">';
}
if((preg_match ("/\bjpg\b/",$row['media2'])) || (preg_match ("/\bjpeg\b/",$row['media2'])) || (preg_match ("/\bpng\b/i",$row['media2'])) || (preg_match ("/\bgif\b/i",$row['media2']))){
echo '<img style="max-width:300px;" src="media/news/'.$row['media2'].'" class="floatLeftClear" id="border">';
}
if((preg_match ("/\bmp3\b/", $row['media1']))) {
echo ' <p id="audioplayer_'.$number1.'" class="floatLeftClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number1.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media1'].'"});
</script>';
echo '<br>';
}
if((preg_match ("/\bmp3\b/", $row['media2']))) {
echo ' <p id="audioplayer_'.$number2.'" class="floatLeftClear">Media Content</p>
<script type="text/javascript">
AudioPlayer.embed("audioplayer_'.$number2.'", {soundFile: "http://kiddiessupportscheme.org/media/news/'.$row['media2'].'"});
</script>';
echo '<br>';
}
echo stripslashes(nl2br($row['text']));
echo '<br><br>';
echo stripslashes($row['author']);
echo '</div>';
echo '<p align="right" id="seperater"><a href="index2.php?op=News#top">Top</a><img src="images/seperater.jpg" width="950" height="6" style="border:none;" /></p>';
}
$number1++;
$number1++;
$number1++;
$number2++;
$number2++;
$number2++;
$counter++;
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于你的第一个问题:
你只需要编辑你的css文件:
更改:
到:
对于你的第二个问题,我找到了这个链接: http://www.sitepoint.com/forums/3713338-post5.html 这正是您需要的解决方案。
我上面发布的链接中的代码:
to your first problem:
You only have to edit your css file:
Change:
To:
For your second problem, I found this link: http://www.sitepoint.com/forums/3713338-post5.html There is exactly the solution you need.
Code from the link I posted above: