更好的短代码

时间:2014-01-17 14:41:20

标签: php mysql sql mysqli

我想知道是否有更短的代码可以获得相同的结果:

$query      = "SELECT * FROM `test` ORDER BY `id`";
$run        = mysqli_query($link, $query);
$prepare    = mysqli_prepare($link, $query);
$execute    = mysqli_stmt_execute($prepare);
$store      = mysqli_stmt_store_result($prepare);
$row        = mysqli_stmt_num_rows($prepare);
while($row = mysqli_fetch_assoc($run))
{
    $id = $row['id'];
    $name   = $row['name'];
    $phone  = $row['phone'];        
    $email  = $row['email'];
//  .
//  .
//  .
//  .
//  etc code
}

如果您知道更好或更短的方式,请将其作为回复发布..

提前致谢

1 个答案:

答案 0 :(得分:1)

如果您不在其他地方使用任何这些变量,那么您可以将其简化为:

$query      = "SELECT * FROM `test` ORDER BY `id`";
$run        = mysqli_query($link, $query);
while($row = mysqli_fetch_assoc($run))
{
    //Code
}