2017-06-16 7 views
0

ちょうどaspからphpに移動し、データベースレコードをテーブルに表示しようとしています。私は、ビュー内のいくつかのフィールドをバインドさましたが、それは私が最初に気づくのは、私は周りにループが表示されないということですhtmlテーブルのデータベースフィールドをバインドする

<table width="12%" border="0" align="center" cellpadding="5" cellspacing="5"> 
    <tr bgcolor="#EBEBEB"> 
    <td width="17%"><div align="center"><strong>Fullname</strong></div></td> 
    </tr> 
    <tr> 
    <td><?php echo $row['fullname']; ?></td> 
    </tr> 
</table> 
+0

は、あなたがactua行いますすべての結果がありますか? – DevDonkey

+0

はい結果が得られます – user6579134

+0

phpとhtmlは同じファイルにありますか? – nerdlyist

答えて

0

PHP

<?php require_once('Connections/hey.php'); ?> 
<?php 
$sql = "SELECT fullname, city FROM dbo.user"; 
$stmt = sqlsrv_query($conn, $sql); 
if($stmt === false) { 
    die(print_r(sqlsrv_errors(), true)); 
} 

//echo json_encode($stmt); 

$a = Array(); 
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { 
     echo $row['fullname'].", ".$row['city']."<br />"; 
    $a[]= $row; 
} 

//echo json_encode($a); 
sqlsrv_free_stmt($stmt); 

?> 

HTMLを表示されません。あなたのHTMLは次のように抽出されたアレイの上$a 何かを反復する:

<table width="12%" border="0" align="center" cellpadding="5" cellspacing="5"> 
    <tr bgcolor="#EBEBEB"> 
    <td width="17%"><div align="center"><strong>Fullname</strong></div></td> 
    </tr> 
    <?php foreach ($a as $row) {?> 
    <tr> 
     <td><?php echo $row['fullname']; ?></td> 
    </tr> 
    <?php } ?> 
</table> 
+0

Sidenote:テーブル内のループは、テーブル全体ではなく行単位で使用します。 – vaso123

+0

ちょうどcopypastaの間違いありがとう! – PaulSCoder

+0

私はただそれを修正しました) – vaso123

関連する問題