약간의 도움이 필요합니다. 이 코드는 첫 번째 행을 놓치고 그 이유를 모르겠습니다. 웹에서 많은 것을 검색했지만 모든 사람들이 mysql_fetch_array ($ results)에 대해 이야기하지만 내 코드에는 아무 것도 없습니다.첫 번째 행이 누락 된 PHP 및 mysql
이 코드에서 문제가 있습니까?
<?php
// create query
$query = "SELECT * FROM products";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$id = mysql_result($result,$i,"id");
$name = mysql_result($result,$i,"name");
$imageurl = mysql_result($result,$i,"imageurl");
$price = mysql_result($result,$i,"price");
$quantity = mysql_result($result,$i,"quantity");
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table class='table table-hover'>";
echo "<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Image</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$id."</td><td>".$name."</td><td><a href='".$imageurl."' class='fancybox fancybox-effects-e' title='".$name."'><img src='".$imageurl."' alt='".$name."'></a></td><td>€ ".$price."</td><td>".$quantity."</td>";
echo "</tr>";
}
echo "</thead>";
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
무슨 생각? – Nikola
'$ id'를 할당 한 행에서'$ i'를 참조합니다. '$ i'는 어디에서 값을 할당 받았습니까? –
'$ i'는 어디에서 초기화합니까? '$ id'를 초기화하지만 결과를 반복 할 때 결코 다시 설정하지 않으므로 같은 값을 출력 할 것입니다. (다른 네 개의 변수에도 마찬가지 임) – andrewsi