如何遍历mySQL表中的元素(一个字段)

时间:2014-07-27 19:51:30

标签: php mysql

如何编写PHP代码来访问第一个元素,直到列网站的最后一个元素,并将输出传递给另一个PHP函数。

<?php
$mysqli = new mysqli("localhost", "root", "", "wte");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT Website FROM websites";

if ($result = $mysqli->query($query)) {

// PHP code to access the first element till last element of the column Website and to pass the output to another php function  

    }

    /* free result set */
    $result->close();
}

/* close connection */
$mysqli->close();
?>

1 个答案:

答案 0 :(得分:1)

阅读php手册:http://php.net//manual/en/mysqli-result.fetch-assoc.php

while ($row = $result->fetch_assoc()) {
      your_function($row["Website"]);
}