0
내가 무엇을 놓치고 있는지 잘 모르겠습니다. 페이지가 테이블과 함께로드되지만 행에 데이터를 가져 오지 않습니다. 데이터베이스에 연결하여 코드를 편집하기 전에 데이터를 가져 왔습니다. 그리고 첫 번째 줄에는 내가 가지고있는 9 개의 행이 표시됩니다.PHP로 MySQL에서 행으로 데이터를 가져 오는 방법은 무엇입니까?
$rowsfortable
이 과거의 어떤 값이 할당되기 전에 테이블을 인쇄하는 것처럼 그것은 나에게 보이는
<?php if (mysql_num_rows($result) > 0) : ?>
<?php
print '<table class="col-md-12">
<tr>
<th class="col-md-1">Category</th>
<th class="col-md-2">Subcategory</th>
</tr>
<tr>'.$rowsfortable.'
</tr>
</table>';
//Get Category.
while ($row = mysql_fetch_array($result)) {
$qry = "SELECT * FROM general_category WHERE categoryID = {$row['categoryID']}";
$tmpResult = qry($qry);
$tmpRow = mysql_fetch_array($tmpResult);
$category = $tmpRow['category_desc'];
//Get Sub Category.
$qry = "SELECT * FROM general_category WHERE categoryID = {$row['sub_categoryID']}";
$tmpResult = qry($qry);
if (mysql_num_rows($tmpResult) > 0) {
$tmpRow = mysql_fetch_array($tmpResult);
$sub_category = "/ " . $tmpRow['category_desc'];
} else {
$sub_category = '';
}
for ($i=0; $i < count($row); $i++) {
$rowsfortable = "print '<td>' '.$category.' '.$sub_category.'</td>'";
}
}
?>
코드에 주문 문제가 있습니다. – cmorrissey
** 경고 ** : PHP를 배우고 있다면 [mysql_query] (http://php.net/manual)를 사용하지 마십시오. /en/function.mysql-query.php) 인터페이스. PHP 7에서 제거 된 것은 너무 무섭고 위험합니다. [PDO는 배우기가 어렵지 않습니다.] (http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)와 [PHP The Right Way] (http://www.phptherightway.com/)와 같은 가이드가 모범 사례를 설명합니다. 사용자 매개 변수는 ** [제대로 탈출하지 않았습니다] (http://bobby-tables.com/php)이며 악용 될 수있는 [SQL 주입 버그] (http://bobby-tables.com/)가 있습니다. . – tadman
PHP 후에 html을해야합니까? – DDJ