Home  >  Article  >  Backend Development  >  sql traversal results

sql traversal results

WBOY
WBOYOriginal
2016-09-06 08:57:101252browse

Now you can query the activity information of the last 5 days, but I don’t know how to traverse it. Please give me some advice.
sql traversal results

sql traversal results

Reply content:

Now you can query the activity information of the last 5 days, but I don’t know how to traverse it. Please give me some advice.
sql traversal results

sql traversal results

See if there is php in your tag, you can use php to connect to the database to query the results. Generally the result will be an array, just use php to traverse the array

Your ultimate goal is to bind results to a page? ?

If yes, continue.

What binding method do you use to output it directly to the page? ? Or ajax binding? ? Universal code:

<code>// 和你上面的查询的sql一致
$sql = ''; 
$db = new PDO('mysql:host=localhost;dbname=db_name' , $user , $pwd);
$result = $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);

if ($ajax) {
  echo json_encode($result);
  exit;
} else {
  // 结合html输出
  foreach ($result as $v)
   {
      // 执行相关操作....
   }
}</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn