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 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊