记录集中的第一条记录为空。为什么?

问题描述:

为什么第一个记录是空的?这不是空的第一个记录成为第二记录,第一个是空的,它似乎无处记录集中的第一条记录为空。为什么?

这是代码

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

你可以试试吗?

<?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 
} 
?> 

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

您应该使用while语法而不是do...while。在do...while结果不会在第一次迭代时获取,并且您有空白记录。

如果您使用while,您将在第一次迭代时获得数据。

+0

感谢您的explenation – Gunnit

+0

@GregorMaric:welcome! –

它根本不值一提,因为你在while ($row_services = mysql_fetch_assoc($services)) 获取它,它第一次执行后的作品,所以在那个时候,战绩仅为空。使用一个入门控制的循环:)