dongmao3131 2012-06-09 04:30
浏览 36
已采纳

在段落中间插入图像从数据库检索的文本?

I have a MySQL table in which there are two columns , for text and for image separately. But when i retrieve those columns from database and display those on Site page I need to place the Image(from Image Column) at the middle of the paragraph text(which was retrieved from text column ). I have a separate Uploader that upload the image. I am using a text-editor (ckeditor) but it does not let me upload the pics from the computer so I had to do this.

I will Appreciate any suggestion or help.

enter image description here

content Body has the Paragraph Text and img_location has the image url.

  • 写回答

1条回答 默认 最新

  • dtqjbbr5283 2012-06-09 05:07
    关注
    <?php
     $conn = mysql_connect("localhost", "username", "password");
      if(!$conn)
      {
    die('Could not connect '.mysql_error());
      }
      mysql_select_db("dbname");
      $res = mysql_query("select * from `tb_name`");
      while($v=mysql_fetch_array($res))
      {
        $name=$v['content_body'];
        $img=$v['img_location'];
        $count=strlen($name);
        for($i=0;$i < $count;$i++)
          {
           if($i == $count/2)
           echo "<img src='".$img."'/>"." ".$name[$i];
           else
           echo $name[$i];
          }
      }
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建