dongxun1142 2017-04-18 05:00
浏览 25
已采纳

php / sql:不正确回显show数据

i have a problem with my php and sql code. I trying to make code that when i enter some data that related with the database, the output should show 'zero' if the row user_designid equal to 0 and if vice versa it will show 'one'. but the problem is both of output only show the first anwser ('zero').

Php file (co.php is my config)

 <?php
 require "co.php";
 $link = mysqli_connect($h,$u,$p,$db);

 if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
 }
echo "Connected successfully";

$q = "select * from tab_ss_user where User_name ='".$_POST['name']."'";
$result = mysqli_query($link,$q);


if($result){
echo "<table border='1' >
<tr>
<td align=center> <b>user Id No</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Password</b></td>
<td align=center><b>responsibility</b></td></td>";

while($data = mysqli_fetch_row($result))
{   
echo "<tr>";
echo "<td align=center><option>$data[0]</option></td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";

    //this is the problem
if($data['User_DesignID'] == 0 ){
      echo "<td align=center> zero </td>";
 }
else{
      echo "<td align=center> one </td>";
 }


   echo "</tr>";
 }
   echo "</table>";
 }

  else{
   echo ' Failed';
 }
 ?>

that all thank you.

  • 写回答

3条回答 默认 最新

  • doouzlrvb01417498 2017-04-18 06:35
    关注

    You are not referencing the field correctly See enter link description here

    When using mysqli_fetch_row, the result is an associative array so $data['User_DesignID'] will not be referenced correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码