简体   繁体   English

如何在mysql中处理mysql查询

[英]How to handle mysql queries in mysql

I'm starting to learn php+mysql 我开始学习php + mysql

after making a query like this: 在进行这样的查询之后:

$sql = "SELECT * FROM clients";
$query = $mysqli->query($sql);

I need to put in a array to access information right? 我需要放入一个数组来访问信息吗?

$result = mysqli_fetch_all($query);

Do I need to use an array or can I search within $query for info? 我需要使用数组还是可以在$ query中搜索信息?

For all intents and purposes, yes. 出于所有意图和目的,是的。 In most cases, you won't get much useful data out of it. 在大多数情况下,您将无法获得更多有用的数据。 See http://php.net/manual/en/mysqli.query.php for what values it will return. 请参阅http://php.net/manual/en/mysqli.query.php ,了解它将返回的值。

That said, I typically use mysql_fetch_array() with a parameter to have the results put in an associative array - or just use mysql_fetch_assoc() to skip adding parameters. 也就是说,我通常使用mysql_fetch_array()和一个参数将结果放在一个关联数组中 - 或者只是使用mysql_fetch_assoc()来跳过添加参数。 That function will put it into an array you can print out by looping through it. 该函数将把它放入一个数组,你可以通过它循环打印出来。

For instance: 例如:

while($row = mysql_fetch_array($result))
{
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "</tr>";
}

is part of an example from http://www.w3schools.com/php/php_ajax_database.asp - which is a rather good reference. http://www.w3schools.com/php/php_ajax_database.asp的一个例子的一部分 - 这是一个相当不错的参考。

mysqli_fetch_all将返回一个关联或数字数组,然后您可以使用该数组执行任何操作。

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

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