2011-11-19 99 views
0

爲什麼第一個記錄是空的?這不是空的第一個記錄成爲第二記錄,第一個是空的,它似乎無處記錄集中的第一條記錄爲空。爲什麼?

這是代碼

mysql_select_db($database_webiceberg, $webiceberg); 
$query_services = "SELECT 
services.dynamic_price, 
services.database_price 
from services 
where lang=2 " ; 

$services = mysql_query($query_services, $webiceberg) or die(mysql_error()); 

的這部分代碼是身體

<?php do { 
     $title = $row_services['dynamic_price']; 
     $database_price = $row_services['database_price']; 
     $id = $row_services['id_services']; 

    ?> 
    <tr id="<?php echo $id;?>"> 
    <td class="matrixItem" > 
    <a href="WebDesign.php?cattegory=<?php echo $cattegory; ?>" id="nigga"><?php echo $title; ?></a> 
    </td> 
    </tr> 
    <?php } while ($row_services = mysql_fetch_assoc($services)); 
    ?> 

我刪除在該部分代碼給它更多的語法和怎麼把代碼我刪除是多餘

+0

而不是'DO ... WHILE',爲什麼不嘗試一個簡單的'WHILE'?您當前的WHILE命令位於底部,因此第一個循環可能不會提取任何數據。 – Nonym

回答

2

你可以試試嗎?

<?php 
while ($row_services = mysql_fetch_assoc($services)) { 
    $title = $row_services['dynamic_price']; 
    $database_price = $row_services['database_price']; 
    $id = $row_services['id_services']; 
    ?> 
    <tr id="<?php echo $id;?>"> 
    <td class="matrixItem" ><a href="WebDesign.php?cattegory=<?php echo $cattegory; ?>" id="nigga"><?php echo $title; ?></a></td> 


    </tr> 
<?php 
} 
?> 
4

do{}塊將之前拼命地跑所以$row_services先爲空。

使用簡單,同時或寫$row_services = mysql_fetch_assoc($services)之前do

<?php 
    while ($row_services = mysql_fetch_assoc($services)): 

     $title = $row_services['dynamic_price']; 
     $database_price = $row_services['database_price']; 
     $id = $row_services['id_services']; 
    ?> 
    <tr id="<?php echo $id;?>"> 
     <td class="matrixItem" > 
      <a href="WebDesign.php?cattegory=<?php echo $cattegory; ?>" id="nigga"><?php echo $title; ?></a> 
     </td> 
    </tr> 
    <?php endwhile; ?> 
+0

這也是正確的 – Gunnit

1

您應該使用while語法而不是do...while。在do...while結果不會在第一次迭代時獲取,並且您有空白記錄。

如果您使用while,您將在第一次迭代時獲得數據。

+0

感謝您的explenation – Gunnit

+0

@GregorMaric:welcome! –

0

它根本不值一提,因爲你在while ($row_services = mysql_fetch_assoc($services)) 獲取它,它第一次執行後的作品,所以在那個時候,戰績僅爲空。使用一個入門控制的循環:)