dongwen1909 2016-10-25 18:06 采纳率: 0%
浏览 41
已采纳

在按钮徽章上显示MySQL查询的输出

I am new to php mysql & have this query where i want to display the output of mysql query on button badge. I have tried the following code Kindly help .

<?php
$con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysqli_select_db($con,"sales");
$sth = mysqli_query($con,"select sum(sal) as Salary from `sales` ");
$result = mysqli_query($con,$sth);
$row = mysqli_fetch_assoc($con,$result);     
echo $row;
?>
<html>
<head>
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<button type="button" class="btn btn-primary">Primary <span class="badge"><?php echo $row; ?></span></button>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongnu4254 2016-10-25 18:10
    关注
    <?php echo ''.$row['Salary'].''; ?>
    

    As long as you have verified the settings and the query is correct the above line should output what you are looking for.

    EDIT

    <?php
     $con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
    mysqli_select_db($con,"sales");
    $sth = "select sum(sal) as Salary from `sales` ";
    $result = mysqli_query($con,$sth);
    $row = mysqli_fetch_assoc($result);  
    

    Try That

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

报告相同问题?

悬赏问题

  • ¥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
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog