如何按字母顺序排列

如何按字母顺序排列

如何按字母顺序排列我的桌子?

这是代码;

<table width="100%">
<tr class="head">
<th>Date of entry</th>

<th>Date of Baptisim</th>
<th>Name of the Child</th>

<th>Birthday</th>
<th>Mother</th>
<th>Father</th>
<th>Mother's Address</th>
<th>Father's Address</th>
<th>Current Address</th>
<th>Ninong/Ninang</th>

<th>Amount Paid</th>
<th>Priest</th>
</tr>
<?php

$sql=mysql_query("select * from persons");
$i=1;
while($row=mysql_fetch_array($sql))
{
$da=$row['da'];
$entry=$row['entry'];
$name=$row['name'];

$bday=$row['bday'];
$mot=$row['mot'];
$fat=$row['fat'];
$motadd=$row['motadd'];
$fatadd=$row['fatadd'];
$ca=$row['ca'];
$nn=$row['nn'];
$paid=$row['paid'];
$priest=$row['priest'];
if($i%2)

{
?>
<tr id="<?php echo $id; ?>" class="edit_tr">
<?php } else { ?>
<tr id="<?php echo $id; ?>" bgcolor="#f2f2f2" class="edit_tr">
<?php } ?>
<td class="edit_td">
<span class="text"><?php echo $da; ?></span>
</td>

<td>
<span class="text"><?php echo $entry; ?></span>
</td>

<td>
<span class="text"><?php echo $name; ?></span>
</td>
<td>
<span class="text"><?php echo $bday; ?></span>
</td>
<td>
<span class="text"><?php echo $mot; ?></span>
</td>
<td>
<span class="text"><?php echo $fat; ?></span>
</td>
<td>
<span class="text"><?php echo $motadd; ?></span>
</td>
<td>
<span class="text"><?php echo $fatadd; ?></span>
</td>
<td>
<span class="text"><?php echo $ca; ?></span>
</td>
<td>
<span class="text"><?php echo $nn; ?></span>
</td>

<td>
<span class="text"><?php echo $paid; ?></span>
</td>
<td>
<span class="text"><?php echo $priest; ?></span>
</td>
</tr>

<?php
$i++;
}
?>

</table>




form action="addper.php" method="post">
<div style="margin-left: 48px;">
    Date Of Entry:<input name="da" type="date" />
    </div>
    <div style="margin-left: 48px;">
    Date Of Baptisim:<input name="entry" type="date" />
    </div>
    <br />
    <div style="margin-left: 48px;">
    Name of the child:<input name="name" type="text" />
    </div>
    <br />
    <div style="margin-left: 100px;">
    Birthday:<input name="bday" type="date" />
    </div>
    <br />
    <div style="margin-left: 105px;">Mother:
      <input name="mot" type="text" />
    </div>
    <br />
<div style="margin-left: 105px;">
    Father:<input name="fat" type="text" />
    </div>
    <br />
<div style="margin-left: 47px;">
    Mother's Address:<input name="motadd" type="text" />
    </div>
    <br />
<div style="margin-left: 48px;">
    Father's Address:<input name="fatadd" type="text" />
    </div>
    <br />
<div style="margin-left: 50px;">
    Current Address:<input name="ca" type="text" />
    </div>
    <br />
<div style="margin-left: 60px;">
    Ninong/Ninang:<input name="nn" type="text" />
    </div>
    <br />
    <div style="margin-left: 75px;">
    Amount Paid:<input name="paid" type="text" />
    </div>
    <br />
    <div style="margin-left: 110px;">
    Priest:<input name="priest" type="text" />
    </div>
    <br />

    <div style="margin-left: 127px; margin-top: 14px;"><input name="" type="submit" value="Add" /></div>
</form>
</div>

最佳答案

在SQL查询中添加ORDER BY子句:

SELECT * FROM persons ORDER BY name

10-07 14:45