donglaogu3788 2016-09-02 21:49
浏览 37
已采纳

如何使用php函数在标签上显示数据库内的数据

I have a database with titles and I want to display them inside of a tag.

<?php 
require 'mainphp.php';

    if (isset($_GET['val'])) {
        $id=$_GET['val'];

        if ($id==1) {
            echo "<br>";
            echo '<div class="row" >';
            for ($i=1; $i < 20; $i++) { 
                    echo '<div class="col-xs-4 col-sm-3 col-md-2" >';
                        echo ('<a href="kwdikoi.php?id='.$i.'" type="button" class="btn btn-warning btn-lg" >'.displayData("kwdikoi",$i, "title").'</a>');
                    echo '</div>';
            }
            echo '</div>';
        }elseif ($id==28) {
            # code...
        }elseif ($id==33) {
            # code...
        }
    }elseif (isset($_GET['id'])) {
        $id=$_GET['id'];
        displayData('kwdikoi',$id,'essence');
    }

    ?>

mainphp.php

function displayData($table,$line,$column){

//open SQL CONNECTION
$conn = mysqli_connect('localhost','root','alex','labels');
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
mysqli_query($conn,'set character set UTF8');
mysqli_query($conn,"SET NAMES 'utf8'");
mysqli_set_charset($conn,"utf8");

//SELECT the row from our table 
$query = "SELECT * FROM ".$table." WHERE id ='".$line."'";
$result = mysqli_query($conn,$query);

if (mysqli_num_rows($result) > 0) {
// output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo $row[$column];
    }
}else{
    echo "There is no ".$column." in our database.".mysqli_error($conn);
}
//."<br>".$row['title']."<br>".$row['smallindex']."<br>".$row['mainindex']."<br>";
// close SQL connection
mysqli_close($conn);

}

The displayData() is a function that echoes the title . The results that I get is the title outside of the button e.g title[empty button] , and I want the title inside the button e.g [title] .

  • 写回答

1条回答 默认 最新

  • douju2599 2016-09-03 15:31
    关注

    Ok, i found it.
    // Strings can be passed individually as multiple arguments
    echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);

    http://php.net/manual/en/function.echo.php

    Using commas and single quotes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch