我想從數據庫中獲取每一步的增加的步數。這裏是我的代碼:自動增加一個變量
//get the project steps
$ID=mysqli_real_escape_string($con,$_GET['id']);
$projSteps="SELECT project_steps.projectStepDesc,project_steps.projectID FROM project_steps WHERE project_steps.projectID=$ID";
$results1 = mysqli_query($con,$projSteps);
if (!$results1) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
if (mysqli_num_rows($results1) > 0){
echo '<h2>Project Steps:</h2>';
while ($rows = mysqli_fetch_assoc($results1))
{
$a=1;
echo "Step ". $a++ ."<br />";
$psteps=$rows['projectStepDesc'];
echo '<div id="steps">';
echo "$psteps";
echo '</div>';
}}//end project steps
這只是輸出每一步的第1步。我試圖讓它說第1步,第2步,第3步等。我怎樣才能做到這一點?
在'while循環開始之前初始化'$ a = 1' _before_。這很關鍵,或者在每次迭代時重置爲1。 –
把** $ a = 1; ** **外**,而 – donald123