简体   繁体   English

在PHP中显示两个值

[英]Display two values in php

Hi have a database with several values in one table but when i try to display the values there is nothing displayed. 嗨,在一个表中有一个包含多个值的数据库,但是当我尝试显示这些值时,没有任何显示。 The connection to the database is OK but the code does not display any values. 与数据库的连接正常,但是代码不显示任何值。

The table name is beraknings_varden and the values i want to display on the screen is stigning and diameter . 表名称beraknings_varden ,我想在屏幕上显示的值被stigningdiameter

Here is the code that should display the values 这是应该显示值的代码

$result = mysqli_query("SELECT * FROM beraknings_varden") or die(mysqli-error());

while ($row = mysqli_fetch_array ( $result)){ 
   echo $row[stigning].", ";
   echo $row[diameter];
   echo "<br />";
}

mysqli_close($opendb);

?>

You have some issues in your code: 您的代码中有一些问题:

  • You need to add connection link identifier in mysqli_query function. 您需要在mysqli_query函数中添加连接链接标识符。
  • Don't know what is this mysqli-error() this should be mysqli_error() . 不知道这是什么mysqli-error()应该是mysqli_error()

Modified code : 修改后的代码

$result = mysqli_query($opendb ,"SELECT * FROM beraknings_varden") or die(mysqli_error($opendb)); 

while ($row = mysqli_fetch_array($result))
{ 
    echo $row['stigning'].", "; 
    echo $row['diameter']; echo "<br />"; 
} 
mysqli_close($opendb);

Side note : 旁注

You must need to read this manual ( mysqli_query ) . 您必须阅读本手册mysqli_query

Here we go, first you have to more careful when doing some database query. 在这里,首先,您在执行一些数据库查询时必须更加小心。

You miss to give the connection mysqli_query($opendb, "your Qry") where its mandatory. 您错过了给予mysqli_query($opendb, "your Qry")强制连接的地方。

Skip over spaces when use the function of mysql. 使用mysql功能时跳过空格。 Look at there, mysqli_fetch_array($result) , what you write mysqli_fetch_array ( $result) . 从那里看, mysqli_fetch_array($result) ,写的是mysqli_fetch_array ( $result)

Your new Query: Try this, may be its helpful. 您的新查询:尝试一下,可能会有所帮助。

<?php 
    $result = mysqli_query($opendb, "SELECT `stigning`, `diameter` FROM beraknings_varden");

    while ($row = mysqli_fetch_array($result)){ 
       echo $row['stigning'].", ";
       echo $row['diameter'];
       echo "<br />";
    }
    mysqli_close($opendb);
?>

Simply this is also Okey, 简而言之,这也是Okey,

mysqli_fetch_array($result);

But you may use some specification. 但是您可以使用一些规范。

// Associative array
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);

// Numeric array
$row=mysqli_fetch_array($result,MYSQLI_NUM);

you can also free the resource. 您还可以释放资源。

// Free result set
mysqli_free_result($result);

you are missing qutation inside the square brackets. 您在方括号内缺少qutation。

echo $row['stigning'].", ";

echo $row['diameter'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM