是否可以在PHP中不使用while循环来获取所有数据

时间:2016-08-26 06:04:53

标签: php

我这里有一张大表,其中包含特定数据的所有信息,我试图回复所有信息,但不使用while loop这可能吗?

以下是我想要做的事情:

这是我的问题:

$query = "SELECT * FROM `info` WHERE `id` = ?";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, 's', $_GET['id']);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $id, $full_name, $phone_number, $crew_rank,$date_of_birth,$age,$telephone_number,$vessel,$place_of_birth,$religion,$joining_date,$citizenship,$civil_status,$sss_number,$joining_port,$shoe_size,$boiler_size,$ht,$wt,$last_vessel,$address,$depedent1_fullname,$depedent2_fullname,$depedent3_fullname,$dependent1_address,$dependent2_address,$dependent3_address,$dependent1_telnumber,$dependent2_telnumber,$dependent3_telnumber,$dependent1_relationship,$dependent2_relationship,$dependent3_relationship,$dependent1_dob,$dependent1_place_of_birth,$dependent2_dob,$dependent3_dob,$passport_number,$passport_date_issued,$passport_date_expiry,$sirb_number,$sirb_date_issued,$sirb_date_expiry,$src_number,$src_position,$src_date_issued,$yellow_fever_number,$yellow_fever_date_issued,$yellow_fever_date_expiry,$us_visa_number,$us_visa_type,$us_visa_date_issued,$us_visa_date_expiry,$australia_number,$australia_type,$australia_date_issued,$australian_date_expiry,$mar_license_position,$mar_license_number,$mar_license_date_issued);

这就是我试图用表格做的事情:

<table border="1" style="table-layout: fixed;" align="center">
  <caption class="center">PERSONAL</caption>
  <tr>
    <th align="left">NAME: </th>
    <td colspan="3"><input type="text" name="full_name" value="<?php echo $full_name; ?>" size="37"></td>
    <th colspan="1" align="left">MOBILE: </th>
    <td><input type="text" name="phone_number" value="<?php echo $phone_number; ?>" size="11"></td>
    <th align="left">RANK: </th>
    <td><input type="text" name="crew_rank" value="<?php echo $crew_rank; ?>" size="10"></td>
  </tr>

注意:注意每个表格行中的值

谢谢

1 个答案:

答案 0 :(得分:0)

你不应该害怕使用循环。你可以打开PHP标签,写下你的代码,关闭它们,再写一次HTML,然后再多次。

看看这个简单的例子:

<?php while ($row = mysqli_fetch_assoc($result)) { ?>
    <input type="text" name="full_name" value="<?php echo $result['full_name']; ?>" size="37">
<?php } ?>