-1

有人可以帮我结合这两个迭代,让两个数组项都显示在我的网页上吗?我要做的是在我的网页中显示 videoURL 和相应的 GroupName。

第一的:

try
{
 $sql = 'SELECT URL from videoclip';
 $result = $pdo->query($sql);

}
catch (PDOException $e)

{
 $error ='Error fetching videos:'.$e->getMessage();
 include'error.html.php';
 exit();
}

while ($row = $result->fetch())
{
  $URLS[] = $row['URL'];
}

include 'index.html.php';

第二:

try
{
  $sql = 'SELECT GroupName from videoclip';
  $result = $pdo->query($sql);
}
catch(PDOException $e)
{
 $error ='unable to fecth data:'.$e->getMessage();
 include'error.html.php';
 exit();
}

while ($row = $result->fetch())
{
  $GroupNames[] = $row['GroupName'];
}
include 'index.html.php';
4

1 回答 1

2

只需组合您的查询,然后构建一个多维数组传递给index.html.php

try
{
  $sql = "SELECT URL, GroupName FROM videoclip";
  $result = $pdo->query($sql);
}
catch(PDOException $e)
{
  $error = 'unable to fetch data: '.$e->getMessage();
  include'error.html.php';
  exit();
}
$URLS = array();
while ($row = $result->fetch())
{
  $URLS[] = array('URL' => $row['URL'], 'GroupName' => $row['GroupName'] );
}

include 'index.html.php';
于 2012-11-04T17:09:59.683 回答