duanchen1937 2016-04-04 17:01 采纳率: 0%
浏览 60
已采纳

在自动填充的PHP表之间放置文本

I'm currently working on a table that contains 'Name', 'Info', 'Price' and 'Duration'. However the PHP-Script is connected to a database.

I want to autofill the tablecells: 'Name', 'Price', 'Duration' via the Database by using PHP and SQL and that works perfectly fine for me. Though, I want to customize the content that's in the individual Info cells (e.g. Readmore jQuery and redirect to other pages).

I tried a little bit with using tags inside the Database and other weird stuff which, obviously, didn't work.

Is there a more elegant way of solving my problem than setting up a complete normal table without PHP/SQL, where I'd have to put in every bit of data about Name,Price and Duration manually?

<table class="table table-bordered table-hover tablesorter row sortable">
    <thead>
      <tr>
        <th class="header">Name</th>
        <th class="hidden-xs">Info</th>
        <th>Price (in Euro)</th>
        <th>Duration</th>
      </tr>
    </thead>
    <tbody>

<?php


//Connect to Database
$db=mysql_connect ("xxxx", "xxxx", "xxxx") or die ('Oops! Da hat wohl' . mysqli_error(). 'Mist gebaut'); 

//Choose Database
$mydb=mysql_select_db("massageke_de");

//Query Database
$sql="SELECT * FROM Angebote";


//-run the query against the mysql query function
$result=mysql_query($sql); 

//Show Results
while($row=mysql_fetch_array($result)){


//Start table ?>

<tr>
        <td class="col-sm-2"><?php echo $Name =$row['Name'] ; ?></td>

        <!--In this <td>-tag I want to put long textes with links-->
        <td class="hidden-xs col-sm-5">echo $Name =$row['Info'];?<</td> 

        <td class="col-sm-2"><?php echo $Preis =$row['Preis']; ?></td>
        <td ckass="col-sm-1"><?php echo $Dauer =$row['Dauer']; ?></td>
</tr>
<?php } ?>


    </tbody>
  </table>

Thanks in advance for helping. Don't bother asking me additional questions.

P.S.: I hope you can help, without needing the CSS of Bootstrap, that I used.

P.P.S.:I know that my PHP-Script is not protected against PHP-Injection (but I want to and will learn how to secure it)

Edit: As Jester asked for it. I made it quickly with photoshop because I think an image can express much better, what I want to achieve, than my poorly coding-skills. Get to the image

  • 写回答

1条回答 默认 最新

  • doukui4786 2016-04-04 17:33
    关注

    Seems to me like the easiest way would be to just edit the info column in the database for each? If you want to do it in php i'd suggest making an array using the names (ids would be better but it seems you don't have access to those?) as keys:

    $info['Aroma Teilkoerper'] = "Text about aroma teilkoerper";
    $info['Aroma Ganzkoerper'] = "Text about aroma ganzkoerper";
    

    and so on until you have all. Then in the loop:

    //Show Results
    while($row=mysql_fetch_array($result)){
    
    
    //Start table ?>
    
    <tr>
        <td class="col-sm-2"><?php echo $Name =$row['Name'] ; ?></td>
    
        <!--In this <td>-tag I want to put long textes with links-->
        <td class="hidden-xs col-sm-5">echo $Name =$info[$row['Name']];?></td> 
    
        <td class="col-sm-2"><?php echo $Preis =$row['Preis']; ?></td>
        <td ckass="col-sm-1"><?php echo $Dauer =$row['Dauer']; ?></td>
    </tr>
    <?php } ?>
    

    Hoping that is a workable solution for you? (also you had a syntax error in your closing php tag.

    echo $Name =$row['Info'];?<  // <----- should be ?> of course
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题