2

在我显示区域记录之前,尽管我在数据库表中有记录

HTML

<div class="pub_fot_sec_menu pub_fot_list_fst">
    <h2><a href="index.php?pages=zilla.php&val=1">Kosi</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=2">Mechi</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=3">Sagarmatha</a></h2>
</div>
<div class="pub_fot_sec_menu pub_fot_list_sec">
    <h2><a href="index.php?pages=zilla.php&val=6">Bagmati</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=7">Janakpur</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=8">Narayani</a></h2>
</div>
<div class="pub_fot_sec_menu pub_fot_list_thrd">
    <h2><a href="index.php?pages=zilla.php&val=9">Dhawalagiri</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=10">Gandaki</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=11">Lumbini</a></h2>
</div>
<div class="pub_fot_sec_menu pub_fot_list_frth">
    <h2><a href="index.php?pages=zilla.php&val=12">Bheri</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=13">Karnali</a></h2>
    <h2><a href="index.php?pages=zilla.php&val=14">Rapti</a></h2>
</div>

现在我想使用 while 或任何对我有用的方法来获取区域记录!

<?php
$sql="select * from tb_zone";
$res =mysql_query($sql);
while($data =mysql_fetch_array($res))
    {
        // want do display zone record in the above html output format
    }
?>

任何帮助,将不胜感激!

4

2 回答 2

2

尝试这个

 <?php
$class = array ('pub_fot_sec_menu pub_fot_list_fst','pub_fot_sec_menu pub_fot_list_sec','pub_fot_sec_menu pub_fot_list_thrd','pub_fot_sec_menu pub_fot_list_frth'); 
$sql="select * from tb_zone";
$res =mysql_query($sql);
$j=0;
$i=0;
while($data =mysql_fetch_array($res))
    {
       if($i==0)
       {   echo '<div class="'.$class[$j].'">';   }

         echo  '<h2><a href="index.php?pages=zilla.php&val='.$data["value"].'">'.$data["zone"].'</a></h2>';

         if($i%2==0 && i > 0)
       {   echo '</div>';  $j++;$i=0; }
       else{    $i++;    }




    }



 ?>
于 2013-06-16T13:45:48.913 回答
0

只使用这种类型

while($data =mysql_fetch_array($res))
{

echo
'
<div class="pub_fot_sec_menu pub_fot_list_fst">
    <h2><a href="index.php?pages=zilla.php&val='.$data['value'].'">'.$data['zone'].'</a></h2>
';
}
于 2013-06-16T13:30:58.100 回答